我要的音视频文章 MPMoviePlayerViewController VS MPMoviePlayerController AVAudioPlayer MPMusicPlayerControll


http://www.cnblogs.com/pengyingh/articles/2383466.html

音频视频

原文地址:音频视频 作者:家明

视频播放 MediaPlayer.framework

MPMoviePlayerViewController VS MPMoviePlayerController

 

 

MPMoviePlayerViewController

MPMoviePlayerController

版本支持

Available in iOS 3.2 and later.

Available in iOS 2.0 and later.(多数属性支持3.2)

大小

只支持全屏播放  如果addsubview 不支持横竖屏

可全屏也可自己设置frame

调用

presentMoviePlayerViewControllerAnimated: 

 

dismissMoviePlayerViewControllerAnimated

addsubview:

属性

moviePlayer

[mMPVC. moviePlayer play];

 

 

BOOL shouldAutoplay

NSTimInterval initialPlaybackTime

 

NSTimeInterval duration

MPMovieControlStyle controlStyle

函数

 

initWithContentURL

 

shouldAutorotateToInterfaceOrientation

 

initWithContentURL

 

requestThumbnailImagesAtTimes:timeOption

 

thumbnailImageAtTime:timeOption

 

timedMetadata (4.0)

notification

MPMoviePlayerPlaybackDidFinishNotification

播放完成

 

MPMovieMediaTypesAvailableNotification

视频开始播放 (载入完成)

 

MPMoviePlayerNowPlayingMovieDidChangeNotification

视频开播 (开始载入)

 

MPMoviePlayerPlaybackStateDidChangeNotification

播放状态变化

判断 mediaPlayer.playbackState

 

MPMoviePlayerDidEnterFullscreenNotification

全屏 相关

 

 

 

另外 UIWebview播放方式 方便 但是对一些视频不支持 经测试有的流媒体的 使用 MPMoviePlayerController 可以播放  UIWebview不支持.

 

 MPMoviePlayerController 为单例4.0之后 可使用 AVPlayerLayer 的播放方式 addSubLayer实现多个视频同时播放

player1 = [AVPlayer playerWithURL:[NSURL fileURLWithPath:moviePath]];

     player1.actionAtItemEnd = AVPlayerActionAtItemEndNone;

     [[NSNotificationCenter defaultCenter] addObserver:self

                                                          selector:@selector(playerItemDidReachEnd:)

                                                               name:AVPlayerItemDidPlayToEndTimeNotification

                                                            object:[player1 currentItem]];

     [player1 play];

 

playerLayer1 = [AVPlayerLayer playerLayerWithPlayer:player1];

     playerLayer1.frame = self.bounds;       

          [self.layer addSublayer:playerLayer1];

 

 

参考:

MPMoviePlayerViewController

http://developer.apple.com/library/ios/#documentation/mediaplayer/reference/mpmovieplayerviewcontroller_class/Reference/Reference.html

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

常用方法:

AudioServicesCreateSy

stemSoundID(CFURLR inFileURL,

SystemSoundID *outSystemSoundID)

 

AudioServicesPlay

SystemSound(SystemSoundID inSystemSoundID)

- (id)initWithContentsOfURL:(NSURL *)url error:(NSError*)outError;

 

-  (id)initWithData:(NSData *)dataerror:(NSError *)outError;

 

-  (BOOL)play;

-  (void)pause;

- (void)stop;

applicationMusicPlayer;

 

-  (void)setQueueWithQuery:(MPMediaQuery *)query;

 

-(void)play;

-(void)pause;

-(void)stop;

 

 各个播放器初始化方法:

1 System Sound Services

// 创建路径

NSString*dropMusicPath = [[NSBundle mainBundle] pathForResource:@"bird drop" ofType:@"wav"];

CFURLRefdropURL = (CFURLRef)[NSURL fileURLWithPath:dropMusicPath];

 

//创建系统声音

AudioServicesCreateSystemSoundID(dropURL, &birdDropID);

 

//播放音效

AudioServicesPlaySystemSound(birdDropID);

 

AVAudioPlayer 类

 

// 设置音乐文件路径  

    path = [[NSBundle mainBundle] pathForResource:@"InTheMood" ofType:@"mp3"]; 

   

 

  // 设置 player    url为本地音频文件路径

 player = [[AVAudioPlayer alloc] initWithContentsOfURL:[NSURL fileURLWithPath:path] error:&error];

 

在线播放用data初始化

player = [[AVAudioPlayer alloc] initWithData:receiveData error:&err];

 

 [player play];

 

MPMusicPlayerController

 

 

player = [MPMusicPlayerController applicationMusicPlayer];

 

MPMediaItemCollection *_mediaCollection = [[MPMediaItemCollection alloc]initWithItems:SongList];

self.mediaCollection = _mediaCollection;

[_mediaCollection release];

 

[player setQueueWithItemCollection:mediaCollection];

[player setRepeatMode:MPMusicRepeatModeAll];

 

[player play];

 

 

二 音频后台播放:

 

(1) 设置 AVAudioSession 属性支持

NSError * err;

AVAudioSession*audioSession; 

audioSession = [AVAudioSession sharedInstance]; 

[audioSession setCategory:AVAudioSessionCategoryPlayback error:nil]; 

[audioSession setActive:YES error:nil];

 

(2)  设置工程文件plist属性

[转载]音频视频

三 系统后台控制音频播放

 

 

(1)  重写方法 canBecomeFirstResponder 返回YES

 

- (BOOL)canBecomeFirstResponder

{

    return YES;

}

 

- (void)viewDidLoad {

    [super viewDidLoad];

    [self canBecomeFirstResponder];

}

 

(2) 实现接收RemoteControlEvents方法

 

- (void)viewDidAppear:(BOOL)animated {

 

    [super viewDidAppear:animated];

    [self becomeFirstResponder];

    [[UIApplication sharedApplication] beginReceivingRemoteControlEvents];

 

}

 

- (void)viewWillDisappear:(BOOL)animated {

   

    [super viewWillDisappear:animated];

    [[UIApplication sharedApplication] endReceivingRemoteControlEvents];

    [self resignFirstResponder];

   

}

 

(3)  在回调方法做相应处理

 

- (void) remoteControlReceivedWithEvent: (UIEvent *) receivedEvent {

   

    if (receivedEvent.type == UIEventTypeRemoteControl)

    {

        switch (receivedEvent.subtype)

     {

            case UIEventSubtypeRemoteControlTogglePlayPause:

                                        

                break;

     case UIEventSubtypeRemoteControlPlay:

          break;

     case UIEventSubtypeRemoteControlPause:

          break;

           case UIEventSubtypeRemoteControlPreviousTrack:

                     break;

           case UIEventSubtypeRemoteControlNextTrack:

                break;

            default:

                break;

        }

    }

}


购物商城项目采用PHP+mysql有以及html+css jq以及layer.js datatables bootstorap等插件等开发,采用了MVC模式,建立一个完善的电商系统,通过不同用户的不同需求,进行相应的调配和处理,提高对购买用户进行配置….zip项目工程资源经过严格测试可直接运行成功且功能正常的情况才上传,可轻松复刻,拿到资料包后可轻松复现出一样的项目,本人系统开发经验充足(全领域),有任何使用问题欢迎随时与我联系,我会及时为您解惑,提供帮助。 【资源内容】:包含完整源码+工程文件+说明(如有)等。答辩评审平均分达到96分,放心下载使用!可轻松复现,设计报告也可借鉴此项目,该资源内项目代码都经过测试运行成功,功能ok的情况下才上传的。 【提供帮助】:有任何使用问题欢迎随时与我联系,我会及时解答解惑,提供帮助 【附带帮助】:若还需要相关开发工具、学习资料等,我会提供帮助,提供资料,鼓励学习进步 【项目价值】:可用在相关项目设计中,皆可应用在项目、毕业设计、课程设计、期末/期中/大作业、工程实训、大创等学科竞赛比赛、初期项目立项、学习/练手等方面,可借鉴此优质项目实现复刻,设计报告也可借鉴此项目,也可基于此项目来扩展开发出更多功能 下载后请首先打开README文件(如有),项目工程可直接复现复刻,如果基础还行,也可在此程序基础上进行修改,以实现其它功能。供开源学习/技术交流/学习参考,勿用于商业用途。质量优质,放心下载使用。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值