(作者:aofeng 转载注明出处)
一.MPMoviePlayerController 使用:
1. 引入系统库文件
/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS3.0.sdk/System/library/Frameworks (笔者sdk版本3.0)
2..h文件中#import <MediaPlayer/MediaPlayer.h>
3.调用处实现MPMoviePlayerController
MPMoviePlayerController *mp = [[ MPMoviePlayerController alloc ] initWithContentURL :url ];
if (mp)
{
self . moviePlayer = mp;
[mp release ];
self . moviePlayer .scalingMode = MPMovieScalingModeAspectFit;
self .moviePlayer .movieControlMode = MPMovieControlModeDefault ;
[[ NSNotificationCenter defaultCenter] addObserver: self selector :@selector (myMovieFinishedCallback:)
name : MPMoviePlayerPlaybackDidFinishNotification object : self . moviePlayer ];
[self .moviePlayer play];
}
- (void )myMovieFinishedCallback:(NSNotification *)aNotification
{
// add your code
}
4.可能存在的编译错误
.objc_class_name_MPMoviePlayerController , referenced from:
literal-pointer@_OBJC@_cls_refs@MPMoviePlayerController in MediaPlayerViewController.o symbols(s) not found
原因可能是你没有执行第一步操作,或者执行了操作但是系统没有找到响应的路径,如果是后者那种情况可以尝试在project->Edit Active Target "<project-name>"中搜索框内输入:FRAMEWORK_SEARCH_PATH 然后删除默认的库文件路径。笔者的程序就是出现过这种问题,用此方法程序成功运行。