My application plays online streams.
However when user navigates to the next view controller the music stops. Here is the code that plays sound:
- (void)start
{
@synchronized (self)
{
if (state == AS_PAUSED)
{
[self pause];
}
else if (state == AS_INITIALIZED)
{
NSAssert([[NSThread currentThread] isEqual:[NSThread mainThread]],
@"Playback can only be started from the main thread.");
notificationCenter =
[[NSNotificationCenter defaultCenter] retain];
self.state = AS_STARTING_FILE_THREAD;
internalThread =
[[NSThread alloc]
initWithTarget:self
selector:@selector(startInternal)
object:nil];
[internalThread setName:@"InternalThread"];
[internalThread start];
}
}
}
I’ve tried :
dispatch_async(dispatch_get_main_queue(),
^{
[internalThread start];
});
But it doesn’t work. Does anyone have experience with this?
You have to keep a reference to your AS object.
In my case, I’ve wrapped AS in a singleton.