Arun K Sharma
Arun K Sharma

Reputation: 294

How to use single instance of AVAudioPlayers for playing multiple songs?

I want to play multiple songs with single object of AVAudioplayer, I put songs List in scrollview, when user tap on list player view is open but when user go back for other song player play both songs simanteniosly . what I Can do to fix this?

Upvotes: 0

Views: 794

Answers (1)

stigi
stigi

Reputation: 6721

You want to have AVAudioplayer as a kind of singleton. There are different ways of doing so. You "may" want to add it as an instance variable to your app delegate, but you could also want to create a new singleton object around it.

You should check out this great post on singletons and top level data: http://cocoawithlove.com/2008/11/singletons-appdelegates-and-top-level.html

EDIT: I'll give you an example on how to access it if it's a property (audioPlayer) of you app delegate.

MyAppDelegate *appDelegate = [UIApplication sharedApplication].delegate;
AVAudioplayer *myOneAndOnlyPlayer = appDelegate.audioPlayer;

You have to create the ivar & property declaration in you app delegate and create the instance of ACAudioplayer in -applicationDidFinishLaunching:.

Upvotes: 1

Related Questions