Playing Audio

Hiya,

I am using objective c on Xcode, is there away i can link my button which is on a different view controller, to link it to my prevous viewcontroller.

I'm bassically trying to have a button for around 15 pages/ viewcontrollers, the button would play audio and change page, then when the next button is pressed for the next page it would stop the current mp3 audio from playing. Just wondered what the best way to do this would be?

Hiya thankyou for the reply,


Any chance you could send me an example of how it would look as i'm very new to coding, thankyou for the help. if possible i could send you the code i have to see if you could explain how i'd do it ?

Hi,

I have created a demo for you, which demonstrate how you can use NSNotificationCenter in your app. Please search "amitanmol/NSNotificationCenterDemo" on github to download and test. Let me know if you face any issue or need any help. You can raise any issue on my github account also for this.

import AVFoundation



var audioPlayer: AVAudioPlayer!


func playsound() {

let soundUrl=Bundle.main.url(forResource:selectSoundFile!,withExtension: "wav")

do{

audioPlayer = try AVAudioPlayer(contentsOf: soundUrl!)

}catch

{

print(error)

}

audioPlayer.play()

}


It will be useful to every upgraded version

Is it Working Fine.

Playing Audio
 
 
Q