Skip to content

Commit 4e36c0d

Browse files
Nikita Matrosovvladimir-kotikov
authored andcommitted
CB-11529 ios: Make available setting volume for player on ios device
This closes #106
1 parent 0a5a72d commit 4e36c0d

File tree

2 files changed

+40
-1
lines changed

2 files changed

+40
-1
lines changed

src/ios/CDVSound.m

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -270,6 +270,15 @@ - (void)setVolume:(CDVInvokedUrlCommand*)command
270270
if (audioFile.player) {
271271
audioFile.player.volume = [volume floatValue];
272272
}
273+
else {
274+
float customVolume = [volume floatValue];
275+
if (customVolume >= 0.0 && customVolume <= 1.0) {
276+
[avPlayer setVolume: customVolume];
277+
}
278+
else {
279+
NSLog(@"The value must be within the range of 0.0 to 1.0");
280+
}
281+
}
273282
[[self soundCache] setObject:audioFile forKey:mediaId];
274283
}
275284
}

tests/tests.js

Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -709,6 +709,15 @@ exports.defineManualTests = function (contentEl, createActionButton) {
709709
});
710710
}
711711

712+
//set audio volume
713+
function setVolume() {
714+
console.log("setVolume()");
715+
var volume = document.getElementById("volumeInput").value;
716+
if (media1 !== null) {
717+
media1.setVolume(volume);
718+
}
719+
}
720+
712721
//for forced updates of position after a successful seek
713722

714723
function updatePosition() {
@@ -970,6 +979,24 @@ exports.defineManualTests = function (contentEl, createActionButton) {
970979
row:0,
971980
cell:2
972981
}
982+
},
983+
{
984+
id: "setVolumeBtn",
985+
content: "",
986+
tag: "div",
987+
position: {
988+
row: 3,
989+
cell: 0
990+
}
991+
},
992+
{
993+
id: "volumeInput",
994+
tag: "input",
995+
type: "text",
996+
position: {
997+
row: 3,
998+
cell: 1
999+
}
9731000
}
9741001
],
9751002
elementsRecord =
@@ -1022,7 +1049,7 @@ exports.defineManualTests = function (contentEl, createActionButton) {
10221049
div.setAttribute("align", "center");
10231050
contentEl.appendChild(div);
10241051
//Generate and add buttons table
1025-
contentEl.appendChild(generateTable('audioActions', 3, 3, elementsAudio));
1052+
contentEl.appendChild(generateTable('audioActions', 4, 3, elementsAudio));
10261053
createActionButton('Play', function () {
10271054
playAudio();
10281055
}, 'playBtn');
@@ -1055,6 +1082,9 @@ exports.defineManualTests = function (contentEl, createActionButton) {
10551082
createActionButton('Seek To', function () {
10561083
seekAudio('to');
10571084
}, 'seekToBtn');
1085+
createActionButton('Set volume', function() {
1086+
setVolume();
1087+
}, 'setVolumeBtn');
10581088
//get Special path to record if iOS || Blackberry
10591089
if (cordova.platformId === 'ios')
10601090
getRecordSrc();

0 commit comments

Comments
 (0)