音频,视频

来源:互联网 发布:我的世界插件怎么用js 编辑:程序博客网 时间:2024/04/29 21:21

1.AVAudioPlayer,它用来播放本地文件或内存中的数据,异步播放,应该是在另一个线程中播放的。

   内置休眠功能不会影响音频播放:[NSThread sleepUntilDate:[NSDate dateWithTimeIntervalSinceNow:0.1f]];

   只要将 AVAudioPlayer 的 numberOfLoops 属性设为负数,音频文件就会一直循环播放直到调用 stop 方法。

   AVAudioPlayer 一边播放一边缓存Data
   http://www.cocoachina.com/bbs/simple/?t31388.html
 

   处理音频中断:


AVAudioRecorder

MPMoviePlayerController.

MPMediaPickerController.

MPMdeiaQuery

   MPMediaPropertyPredicate

   MPMediaItemCollection.

MPMusicPlayerController.


2.

iPhone OS 主要提供以下了几种播放音频的方法:
    •    System Sound Services
    •    AVAudioPlayer 类
    •    Audio Queue Services
    •    OpenAL

AVAudioPlayer 是 AVFoundation.framework 中定义的一个类,所以使用要先在工程中引入 AVFoundation.framework。我们可以把 AVAudioPlayer 看作是一个高级的播放器,它支持广泛的音频格式,主要是以下这些格式:
■ AAC
■ AMR(AdaptiveMulti-Rate, aformatforspeech)
■ ALAC(AppleLossless)
■ iLBC(internetLowBitrateCodec, anotherformatforspeech)
■ IMA4(IMA/ADPCM)
■ linearPCM(uncompressed)
■ µ-lawanda-law
■ MP3(MPEG-1audiolayer3

虽然 AVAudioPlayer 可以播放很多格式,但是我们在实际开发过程中还是最好使用一些没有压缩的格式,比如 WAVE 文件,这样可以减少系统处理单元的资源占用,以便更好的完成程序的其他功能。另外,在使用 AVAudioPlayer 连续播放 mp3 这类经过压缩的音频文件时,在连接处可能出现一定的间隔时间。

参考

   iPhone 应用开发:音频播放
   http://www.haogongju.net/art/582046


3.播放视频

   示例网络视频资源地址 http://v.youku.com/player/getM3U8/vid/102999102/type/flv/ts/1339575316/v.m3u8

添加MediaPlayer.framework

#import "MediaPlayer/MPMoviePlayerController.h"

   -(void)openMovie:(id)sender
{
    //NSString *path = [[NSBundle mainBundle] pathForResource:@"movie" ofType:@"m4v"];
    //NSURL* url=[NSURL fileURLWithPath:path];
    NSURL* url=[NSURL URLWithString:@"http://v.youku.com/player/getM3U8/vid/102999102/type/flv/ts/1339575316/v.m3u8"];
    MPMoviePlayerController *movieController = [[MPMoviePlayerController alloc] initWithContentURL:url]; //设置要播放的视频的位置
    
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(movieFinish:) name:MPMoviePlayerPlaybackDidFinishNotification object:movieController]; //设置视频播放结束后的回调处理
    
    [movieController play]; //播放视频
    movieController.view.frame = self.view.bounds;
    [self.view addSubview:movieController.view]; //添加view,否则只听声音无图像
}

-(void)movieFinish:(NSNotification*)notification
{
    MPMoviePlayerController *movieController = [notification object];
    [[NSNotificationCenter defaultCenter] removeObserver:self name:MPMoviePlayerPlaybackDidFinishNotification object:movieController];
    [movieController release]; //释放资源
    movieController = nil;
    
    [[UIApplication sharedApplication] setStatusBarOrientation:UIInterfaceOrientationPortrait animated:YES];
}

MPMoviePlayerController 电影播放器—IOS开发

http://blog.csdn.net/iukey/article/details/7311126


ku6网站在ios上用浏览器打开不能播放视频。


4.MPMoviePlayerController的按钮“done”显示为“完成”  

   在项目的配置文件中(.plist文件),加Localization native development region,value为“China”;加Localizations,value为“Chinese (simplified)”,加Localized resources can be mixed,value为“YES”,播放器上的提示都变为中文了。

   http://lxw5214.blog.163.com/blog/static/14147332011819113141180/


5.自定义MPMoviePlayerController的界面

    http://blog.csdn.net/smking/article/details/8434543

    http://www.kaixinwenda.com/article-Leeyehong_self-7963994.html

   http://blog.csdn.net/smking/article/details/8434543


6.对MPMoviePlayerViewController增加AutoRotate相关的类别,仍不能解决UIWebView播放视频不能横屏的问题。代码不会被执行到。

   可以在网页上使用图片自定义处理点击事件,来调用自己定制的播放器。


10.求助:关于流媒体(m3u8)的下载与播放

   http://www.cocoachina.com/bbs/simple/?t93389.html


原创粉丝点击