音频直播退到后台出现卡顿

新手上路,请多包涵

我用的MPMoviePlayerController播放直音频,注册 [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(mediaPlayerPlaybackStateChange:) name:MPMoviePlayerPlaybackStateDidChangeNotification object:nil]通知,-(void)mediaPlayerPlaybackStateChange:(NSNotification *)notification{
switch (appDelegate.player.playbackState) {
case MPMoviePlaybackStatePlaying:
NSLog(@"正在播放...");
break;
case MPMoviePlaybackStatePaused:
NSLog(@"暂停播放.");
[self startPlay];
break;
case MPMoviePlaybackStateStopped:
NSLog(@"停止播放.");
break;
default:
NSLog(@"播放状态:%li",appDelegate.player.playbackState);
break;
}
}
- (void)startPlay
{
NSString *str = @"http://radio.wlhd.org/hls/live.m3u8";
NSURL *urlk = [NSURL URLWithString:str];
[appDelegate.player setContentURL:urlk];
[appDelegate.player play];
}退到后台会走回调的暂停播放方法,然后我又重新加载了一次,退到后台会卡顿,求大神们支招
进入前台我也是重新加载的
NSString *str = @"http://radio.wlhd.org/hls/live.m3u8";
NSURL *urlk = [NSURL URLWithString:str];
[self.player setContentURL:urlk];
[self.player play];

阅读 3.8k
1 个回答
新手上路,请多包涵
  • (void)creatThread
    {
    [NSThread detachNewThreadSelector:@selector(startBackgroundJob:) toTarget:self withObject:nil];
    }
  • (void)startBackgroundJob:(id)sender { //开始线程
    [self performSelectorOnMainThread:@selector(updateProgressView:) withObject:nil waitUntilDone:NO];
    } //更新数据
  • (void)updateProgressView:(id)sender
    {
    NSString *str = @"http://radio.wlhd.org/hls/live.m3u8";
    NSURL *urlk = [NSURL URLWithString:str];
    [appDelegate.player setContentURL:urlk];
    [appDelegate.player play];

}
我用了一个单线程还是不行

推荐问题