0

Here's what I'm looking to do: I have an AVAudioPlayer called primaryPlayer playing a track, and I want it to continue uninterrupted while I transfer the player to secondaryPlayer. I'll then be using the primaryPlayer for a new AVAudioPlayer instance to play alongside the original track.

Maybe it's as simple as this:

secondaryPlayer=primaryPlayer;
primaryPlayer=[[AVAudioPlayer alloc] initWithContentsOfURL:songURL error:nil];

*these two variables are properties of the class, hence their lack of definition.

I'm worried that I may be missing something. For instance, does this code just set the two variables to point to the same memory address? So that after the second line of code, both variables correspond to the same player?

I think this may be more of an Objective C (or maybe just C) question than anything else, but thanks for reading and any "pointers" on this would be terrific! :)

4

1 回答 1

0

假设primaryPlayerplayer 指向AVAudioPlayeraddress 处的有效实例0x1234并且secondaryPlayer具有任意值并且两者都被声明为strong属性。

secondaryPlayer=primaryPlayer;

现在两个变量都指向同一个对象(在 address 0x1234)。

primaryPlayer=[[AVAudioPlayer alloc] initWithContentsOfURL:songURL error:nil];

secondaryplayer 仍然指向同一个对象,并且作为强引用,该对象仍然存在。primaryPlayer现在指向新创建的对象,所以现在你有两个不同的玩家对象。

于 2013-09-03T00:48:38.183 回答