ios - Volume Slider in swift -


i trying to create slider controls volume of 4 audio files.

here code audio:

var buttonaudiourl  = nsurl(fileurlwithpath: nsbundle.mainbundle().pathforresource("audio1", oftype: "mp3")!)  var firstplayer     = avaudioplayer()     var buttonaudiourl2 = nsurl(fileurlwithpath: nsbundle.mainbundle().pathforresource("audio2", oftype: "mp3")!)   var secondplayer   = avaudioplayer()     var buttonaudiourl3 = nsurl(fileurlwithpath: nsbundle.mainbundle().pathforresource("audio3", oftype: "mp3")!)  var thirdplayer = avaudioplayer()     var buttonaudiourl4 = nsurl(fileurlwithpath: nsbundle.mainbundle().pathforresource("audio4", oftype: "mp3")!)  var forthplayer = avaudioplayer()  override func viewdidload() {      super.viewdidload()     // additional setup after loading view, typically nib.     firstplayer  = avaudioplayer(contentsofurl: buttonaudiourl, error: nil)             secondplayer = avaudioplayer(contentsofurl: buttonaudiourl2, error: nil)          thirdplayer  = avaudioplayer(contentsofurl: buttonaudiourl3, error: nil)            forthplayer  = avaudioplayer(contentsofurl: buttonaudiourl4, error: nil) 

i have audio play when each button touched. need slider control volume of each audio file each button.

how should this? have looked @ mpvolumeview class reference on developer.apple, still confused , in developer.apple reference mpvolumeview, talks airplay, can disable that?

i need slider control volume.

you're close!

drag in slider storyboard, , create ib outlet , ib action it.

in ib action code, use firstplayer.volume = slideroutlet.value

since both range 0 1 default, on same scale , can used without scaling. may need declare avaudioplayers more globally , have way of seeing button pressed (e.g. variable stores name of button pressed). way, change correct volume using 4 if statements , don't end changing volume player has not been initialized yet.

let me know if works!


Comments

Popular posts from this blog

javascript - Using jquery append to add option values into a select element not working -

Android soft keyboard reverts to default keyboard on orientation change -

Rendering JButton to get the JCheckBox behavior in a JTable by using images does not update my table -