老實說這篇文章轉貼過來後發現在MPMoviePlayerViewController 這邊有問題
我還是得用addsubview才呈現的出來(也許是個人問題)
原文如下:
MPMoviePlayerViewControl ler VS MPMoviePlayerController
另外 UIWebview播放方式 方便 但是对一些视频不支持 经测试有的流媒体的 使用 MPMoviePlayerController可以播放 但 UIWebview不支持.
因 MPMoviePlayerController 为单例4.0之后 可使用 AVPlayerLayer 的播放方式 addSubLayer实现多个视频同时播放
player1 = [AVPlayer playerWithURL:[NSURL fileURLWithPath:moviePath]];
playerLayer1 = [AVPlayerLayer playerLayerWithPlayer:player1];
参考:
MPMoviePlayerViewControl ler
MPMoviePlayerController
http://developer.apple.com/library/ios/#documentation/mediaplayer/reference/MPMoviePlayerController_Class/Reference/Reference.html
音频播放
AVFoundation.framework
System Sound Services
|
AVAudioPlayer 类
|
MPMusicPlayerController
| |
特点
|
播放短音效
|
播放任意长度音频
|
播放本地ipod音乐
|
版本
|
ios 2.0 or later
|
ios 2.2 or later
|
ios 3.0 later
|
属性
|
playing,duration,currentTime,
|
repeatMode,currentPlaybackTime,numberOfLoops
| |
常用方法:
|
AudioServicesCreateSyste
AudioServicesPlaySystemS
|
- (id)initWithContentsOfURL:(NSURL *)url error:(NSError*)outError;
-
-
-
- (void)stop;
|
applicationMusicPlayer;
-
-(void)play;
-(void)pause;
-(void)stop;
|
一 各个播放器初始化方法:
1 System Sound Services
// 创建路径
NSString*dropMusicPath = [[NSBundle mainBundle] pathForResource:@"bird drop"ofType:@"wav"];
CFURLRefdropURL = (CFURLRef)[NSURL fileURLWithPath:dropMusicPath];
//创建系统声音
AudioServicesCreateSyste mSoundID(dropURL, &birdDropID);
//播放音效
AudioServicesPlaySystemS ound(birdDropID);
2 AVAudioPlayer 类
// 设置音乐文件路径
在线播放用data初始化
player = [[AVAudioPlayer alloc] initWithData:receiveData error:&err];
3 MPMusicPlayerController
player = [MPMusicPlayerController applicationMusicPlayer];
MPMediaItemCollection *_mediaCollection = [[MPMediaItemCollectionalloc]initWithItems:SongList];
self.mediaCollection = _mediaCollection;
[_mediaCollection release];
[player setQueueWithItemCollecti on:mediaCollection];
[player setRepeatMode:MPMusicRepeatModeAll];
[player play];
二 音频后台播放:
(1) 设置 AVAudioSession 属性支持
NSError * err;
AVAudioSession*audioSession;
audioSession = [AVAudioSession sharedInstance];
[audioSession setCategory:AVAudioSessionCategoryPl ayback error:nil];
[audioSession setActive:YES error:nil];
(2) 设置工程文件plist属性
三 系统后台控制音频播放
(1) 重写方法 canBecomeFirstResponder 返回YES
- (BOOL)canBecomeFirstResponder
{
}
- (void)viewDidLoad {
}
(2) 实现接收RemoteControlEvents方法
- (void)viewDidAppear:(BOOL)animated {
}
- (void)viewWillDisappear:(BOOL)animated {
}
(3) 在回调方法做相应处理
- (void) remoteControlReceivedWit hEvent: (UIEvent *) receivedEvent {
}
沒有留言:
張貼留言