Resuming Interrupted Radio Stream using MPMoviePlayerController
Asked Answered
S

1

10

I am developing an online radio app for iOS6 devices. Ive looked for various wrappers to achieve this task. AVPlayer, MPMoviePlayerController etc.

I tried using AVPlayer as it sounds more correct to use it for my purpose as it is audio only application. But soon I came across this problem : Here

Therefore I switched to MPMoviePlayerController and this is what Im trying to do :

    pPlayer = [[MPMoviePlayerController alloc] initWithContentURL:[NSURL URLWithString:@"http://launch.fusionradio.fm:8004"]];
    pPlayer.movieSourceType = MPMovieSourceTypeStreaming;
    pPlayer.view.hidden = YES;

    [[AVAudioSession sharedInstance] setCategory:AVAudioSessionCategoryPlayback error:nil];
    [[AVAudioSession sharedInstance] setActive:YES error:nil];

    [pPlayer prepareToPlay];
    [pPlayer play];

    pPlayer.shouldAutoplay = YES;

    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(StreamStateChanged) name:MPMoviePlayerLoadStateDidChangeNotification object:pPlayer];

In my StreamStateChanged method Im doing :

NSLog(@"Trying to replay");
[pPlayer pause];

[pPlayer play];

pPlayer is MPMoviePlayer. Everything is fine except when there is an interrupt Console spits out the following :

    Took background task assertion (1) for playback stall.
    Ending background task assertion (1) for playback stall.

The number after assertion keeps increasing. and then it recovers from it once the internet connection is stable.

My question is : Is this approach correct? Am I doing something wrong along the way? And Is it ok to ignore that assert message?.

P.S : Please suggest if there is a better approach for developing radio streaming app using different API as opposed to MPMoviePlayerController

Thank you :)

Sizing answered 17/2, 2013 at 21:23 Comment(0)
C
9

You are entirely correct in ignoring those internal assert messages. There is nothing you can do about them.

Camper answered 18/2, 2013 at 10:18 Comment(4)
Thank you Till. I was also confused about these logging messages (...Took background task assertion (n) for playback stall) in a big fat video playing app you might have heard of...Milzie
the streaming in my app stops a lot because of this assertion!!, what can i do?Farther
@Farther you are getting it the wrong way around. That assertion is happening a lot because your streaming runs out of content - check the network connectivity and the stream encoding.Camper
@Camper is there any event callback about these messages ?Crayfish

© 2022 - 2024 — McMap. All rights reserved.