视频播放 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;

一 各个播放器初始化方法:

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;

}

}

}

ios音频视频资料--备用的更多相关文章

  1. iOS 音频视频图像合成那点事

    代码地址如下:http://www.demodashi.com/demo/13420.html 人而无信不知其可 前言 很久很久没有写点什么了,只因为最近事情太多了,这几天终于闲下来了,趁此机会,记录 ...

  2. 《转》iOS音频视频初级开发

    代码改变世界 Posts - 73, Articles - 0, Comments - 1539 Cnblogs Dashboard Logout HOME CONTACT GALLERY RSS   ...

  3. IOS音频视频

    视频播放 MediaPlayer.framework MPMoviePlayerViewController VS MPMoviePlayerController MPMoviePlayerViewC ...

  4. iOS 音频视频制作

    --iOS多媒体 概览 随着移动互联网的发展,如今的手机早已不是打电话.发短信那么简单了,播放音乐.视频.录音.拍照等都是很常用的功能.在iOS中对于多媒体的支持是非常强大的,无论是音视频播放.录制, ...

  5. iOS 音频/视频 学习目录

    参考 iOS原生API  音/视频录制 编辑 https://www.cnblogs.com/kenshincui/p/4186022.html#summary iOS视频编解码常用库比较 http: ...

  6. iOS 直播-获取音频(视频)数据

    iOS 直播-获取音频(视频)数据 // // ViewController.m // capture-test // // Created by caoxu on 16/6/3. // Copyri ...

  7. iOS音频AAC视频H264编码 推流最佳方案

    iOS音频AAC视频H264编码 推流最佳方案 项目都是个人的调研与实验,可能很多不好或者不对的地方请多包涵. 1    功能概况 *  实现音视频的数据的采集 *  实现音视频数据的编码,视频编码成 ...

  8. iOS 微信 音频 视频自动播放

    iOS 微信 音频 视频自动播放 http://www.w3ctech.com/topic/1165

  9. 2015最全iOS开发自学视频资料(基础+实战)

    最全的iOS自学视频,包括c,objective-c,UI等等,没有你找不到的,只有你学不会的,只要你想学,这里都有你所需要的. 推荐教程点这里:http://www.mobiletrain.org/ ...

随机推荐

  1. CentOS7安装和配置FTP

    1. 安装vsftpd #安装vsftpd yum install -y vsftpd #设置开机启动 systemctl enable vsftpd.service # 重启 service vsf ...

  2. CSS 수직 가운데 정렬 (테이블 없이!) Vertical Centering with CSS

    이 방법은 테이블처럼 만들어서 테이블의 vertical-align 속성을 사용할 수 있도록 를 몇 개 세팅한다. (테이블의 vertical-align 속성은 다른 요소들에서는 굉장 ...

  3. 一个用ASP生成html的新方法

    目前已经有很多生成html的新闻系统,但是都是用的模板,本函数实现把asp页面产生的html代码保存成为一个html文件,这样就没有必要改动原来的页面就可以轻松完成一个生成html的新闻系统了.^_^ ...

  4. ASP怎样获得代码中第一张图片地址

    '把pattern 又修改了下 'code要检测的代码 'http://www.knowsky.com/asp.asp 'leixing html 或者ubb 'nopic 代码没有图片时默认值 fu ...

  5. Android更改桌面应用程序launcher的两种方式

    http://blog.csdn.net/mdx20072419/article/details/9632779/ launcher,也就是android的桌面应用程序.下图是我正在使用的魅族手机的l ...

  6. Asp.net 定时写入文本记录

    Asp.net 定时写入文本记录 public static string FileAddress = "c:\\TimerLog.txt"; protected void Pag ...

  7. SQLserver中的常量与变量、判断循环语句

    数据库中的变量与常量 数据库中定义变量 [起临时存储数据的作用] ---数据库中定义变量(运行时要从头到尾进行运行,从定义变量开始到赋值) --前面必须加 declare --定义变量 :    de ...

  8. java多线程总结六:经典生产者消费者问题实现

    这是个线程同步的经典例子,源代码如下: <span style="font-size:16px;">package demo.thread; /** *经典生产者与消费 ...

  9. 基于微软EnterpriseLib的框架(一)

    1.框架模型无ORM,重点在数据库建模设计与UI框架设计上 2.多数据库支持(Enterprise Lib 默认仅支持SqlServer和Oracle,需自己扩展才能支持其他数据库,本文已扩展SQLi ...

  10. 程序员面试题精选100题(16)-O(logn)求Fibonacci数列[算法]

    作者:何海涛 出处:http://zhedahht.blog.163.com/ 题目:定义Fibonacci数列如下: /  0                      n=0 f(n)=      ...