使用 MPMoviePlayerController 出现的问题、解决方法和注意事项

 在SDK3.2及SDK4.x中MPMoviePlayerController有下面这些改动,像实现竖屏播放不再需要使用私有API了。

- In 3.1 and earlier versions, MPMoviePlayerController was full-screen only. Playing a movie was straight-forward, create a player, initialize with a file (path or URL) and call a method to start playback – the rest was taken care of for you.

- With 3.2 and later, movies can playback in fullscreen or a custom view, as well as portrait or landscape.

- The notification MPMoviePlayerContentPreloadDidFinishNotification has been deprecated. This notification was used in earlier versions to notify observers that a movie was loaded and ready to play.


根据我的经验,在3.2和4.中使用MPMoviePlayerContriller 有这几点需要注意的:


1、出现有声音,画面为黑屏的情况:

     下面是一段在国外论坛看到的对话:

Technical Q&A QA1240
MPMoviePlayerController plays movie audio but not video
Q: I'm able to successfully play movies using MPMoviePlayerController on iOS 3.1.3. When I run this same code on the iPad and on the iPhone with iOS 4 I can hear the movie audio, but the video is no longer displayed. What's going on?

A: Starting with iPhone iOS 3.2, calling the -play: method still starts playback of the movie but it does not ensure that the movie is visible. In order to display a movie, you must get the new view property from your MPMoviePlayerController object and add that view to your view hierarchy.

大意是说3.2之后的sdk还能相应之前旧的方法,但并不保证在开始播放时视频的画面是可见的,要避免这种请情况的们可以使用以下的代码:

#import <UIKit/UIKit.h>
#import <MediaPlayer/MediaPlayer.h>

MPMoviePlayerController *player = [[MPMoviePlayerController alloc] initWithContentURL:movieURL];
[[player view] setFrame:[myView bounds]]; // 在这里可以自定义播放窗口的位置和大小,但是大小的设置最好按照视屏原本的比例进行设置,
[myView addSubview:[player view]];
[player play];


2、在设置视频播放窗口的时候:[[player view] setFrame:[myView bounds]]; 最好将窗口的长宽比设置为视频的比例,不然系统会进行行自行的调整,并不会完完全全地遵从你的参数。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值