iOS 后台 播放h5 视频、音频  解决方案

来源:互联网 发布:主力建仓优化指标 编辑:程序博客网 时间:2024/06/07 01:32
1.  AVAudioSession *audioSession = [AVAudioSessionsharedInstance];
   
BOOL ok;
   
NSError *setCategoryError =nil;
    ok = [audioSession
setCategory:AVAudioSessionCategoryPlayback
                            
error:&setCategoryError];
   
if (!ok) {
       
NSLog(@"%s setCategoryError=%@",__PRETTY_FUNCTION__, setCategoryError);
    }

2. info.plst ->  App plays audio or streams audio/video using AirPlay

3. webView 暴露 播放器播放的方法 player.play()

4.

   添加一个退到后台UIApplicationDidEnterBackgroundNotification通知->在接收通知的方法里面实现下面的代码:

   NSTimer *timer = [NSTimertimerWithTimeInterval:1.0ftarget:selfselector:@selector(videoPlay)userInfo:nilrepeats:NO];
   [[NSRunLoopcurrentRunLoop]addTimer:timerforMode:NSDefaultRunLoopMode];

  - (void)videoPlay
  {
   [webstringByEvaluatingJavaScriptFromString:@"player.play();"];
  }

5. 注意销毁 timer对象
0 0
原创粉丝点击