AVaudio Player Problem
I am using Avaudio player in our app.I play the song from list after playing when i back to list for s开发者_开发技巧electing another song then fist one is also playing.
I want to stop previous song and then play the other song.
Please help me.
[oldplayer stop];
[newplayer start];
you may also be able to get this behavior by setting your audio session up correctly: say
UInt32 sessionCategory = kAudioSessionCategory_MediaPlayback; // Defines a new variable of type UInt32 and initializes it with the identifier
// for the category you want to apply to the audio session.
AudioSessionSetProperty (
kAudioSessionProperty_AudioCategory, // The identifier, or key, for the audio session property you want to set.
sizeof(sessionCategory), // The size, in bytes, of the property value that you are applying.
&sessionCategory // The category you want to apply to the audio session.
);
It seems that you're creating another AVAudioPlayer instance. Let's say the old one is called "audioPlayer"; you need to stop it using audioPlayer.stop() and then create a new audioPlayer using audioPlayer = new AVAudioPlayer(...) This will ensure that ARC deallocates the old instance of AVAudioPlayer, so it no longer exists.
精彩评论