ios后台播放

来源:互联网 发布:网络监控方案 编辑:程序博客网 时间:2024/05/16 13:41

iphone上边后台运行修改配置文件 添加Required background modes



然后再程序里适当的位置调用如下代码

-(void)activeBackGroundPlayer{    /**/    [[AVAudioSession sharedInstance] setDelegate: self];    [[AVAudioSession sharedInstance] setCategory: AVAudioSessionCategoryPlayback error: nil];    UInt32 doSetProperty = 0;    AudioSessionSetProperty (kAudioSessionProperty_OverrideCategoryMixWithOthers,sizeof (doSetProperty),&doSetProperty);    NSError *activationError = nil;    [[AVAudioSession sharedInstance] setActive: YES error: &activationError];  }

播放器类 继承

UIApplicationDelegate

最后创建播放器的时候设置委托到self就可以了

player = [[AVAudioPlayer alloc]initWithContentsOfURL:fileURL error:nil];        [player prepareToPlay];        [player setDelegate:self];        [player play];


原创粉丝点击