Search code examples
objective-cios4avaudioplayeravfoundation

check if music is played


i use avaudioplayer to play own music in my app. is there a possibility to check if music from the avaudioplayer is playing?


Solution

  • Use the playing property, i.e.:

    AVAudioPlayer *audioplayer;
    if(audioplayer.playing){
       //do what you want here
    }
    

    Also refer to the class reference of AVAudioPlayer.

    The class reference states you shouldn't poll this property though. If you want to find out if a song has finished playing, use an AVAudioPlayerDelegate. The audioPlayerDidFinishPlaying:successfully: function will inform you when the audio player finished playing audio.