Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Resuming Interrupted Radio Stream using MPMoviePlayerController

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 :)

like image 793
Gamer Avatar asked Feb 17 '13 21:02

Gamer


1 Answers

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

like image 117
Till Avatar answered Sep 18 '22 06:09

Till