后台播放音乐
来源:互联网 发布:linux密码修改 编辑:程序博客网 时间:2024/06/06 10:44
当退出程序的时候,在后台可以继续播放
#import "ViewController.h"#import <AVFoundation/AVFoundation.h>@interface ViewController (){ AVAudioPlayer* player;}@end@implementation ViewController- (void)viewDidLoad { [super viewDidLoad]; // Do any additional setup after loading the view, typically from a nib. dispatch_async(dispatch_get_global_queue(0, 0), ^{ //设置可以后台播放音乐,音频会话对象 AVAudioSession* session=[AVAudioSession sharedInstance]; if ([session setCategory:AVAudioSessionCategoryPlayback error:nil]) { NSLog(@"后台播放设置成功"); }else NSLog(@"后台播放设置失败"); //播放音乐 NSString* filePath=[[NSBundle mainBundle]pathForResource:@"像梦一样自由" ofType:@"mp3"]; NSData* data=[NSData dataWithContentsOfFile:filePath]; player=[[AVAudioPlayer alloc]initWithData:data error:nil]; if (player!=nil) { if ([player prepareToPlay]) { [player play]; } } });}- (void)didReceiveMemoryWarning { [super didReceiveMemoryWarning]; // Dispose of any resources that can be recreated.}@end
阅读全文
0 0
- ios后台播放音乐
- iOS后台播放音乐
- ios 音乐后台播放
- iOS后台播放音乐
- iOS后台播放音乐
- 后台播放音乐
- iOS后台播放音乐
- iOS后台播放音乐
- iOS后台播放音乐
- 后台播放音乐
- iOS后台播放音乐
- iOS后台播放音乐
- iOS 后台播放音乐
- iOS_33_音乐后台播放
- iOS后台播放音乐
- iOS 后台播放音乐
- iOS 后台播放音乐
- iOS 后台播放音乐
- LeetCode-16:3Sum Closest
- 矩阵快速幂
- Bootstrap中缩略图
- codeforces 830C Bamboo Partition
- seetaface 人脸检测算法简析
- 后台播放音乐
- 操作系统之进程
- LeetCode-17:Letter Combinations of a Phone Number
- jQuery 遍历查找到的每一个结果
- 使用input读取文件
- 各种正则验证
- 深入理解Python中的进程
- 【补充】关于ARM的PC指针异常返回处理(PC+8,PC+4,PC-4,PC-8情况)
- poj-3734