//聯(lián)系人:石虎QQ: 1224614774昵稱:嗡嘛呢叭咪哄
/**
注意:1.先看gif
2.看截圖
3.看代碼
*/
一顽决、gif 圖:
二、截圖:
圖-1:
圖-2:
三勿侯、實現(xiàn)代碼:
#import"ViewController.h"
#import//視頻播放器
@interfaceViewController()
//播放視圖
@property(strong,nonatomic)IBOutletUIView*movieView;
//播放按鈕
- (IBAction)play:(id)sender;
//播放電影控制器
@property(nonatomic,strong)MPMoviePlayerController*moviePlayer;
@end
@implementationViewController
- (void)viewDidLoad {
[superviewDidLoad];
//1.創(chuàng)建本地URL(也可創(chuàng)建基于網(wǎng)絡(luò)的URL)
NSURL* movieUrl = [[NSBundlemainBundle]URLForResource:@"aaa"withExtension:@"mp4"];
//使用指定URL創(chuàng)建MPMoviePlayerController
//2. MPMoviePlayerController將會播放該URL對應(yīng)的視頻
_moviePlayer= [[MPMoviePlayerControlleralloc]initWithContentURL:movieUrl];
//3.設(shè)置該播放器的控制條風(fēng)格佣盒。
_moviePlayer.controlStyle=MPMovieControlStyleEmbedded;
//4.設(shè)置該播放器的縮放模式
_moviePlayer.scalingMode=MPMovieScalingModeAspectFit;
[_moviePlayer.viewsetFrame:CGRectMake(0,0,380,320)];
}
//點擊播放按鈕
- (IBAction)play:(id)sender
{
//添加視頻顯示內(nèi)容
[self.movieViewaddSubview:_moviePlayer.view];
//添加視頻聲音內(nèi)容
[_moviePlayerprepareToPlay];
}
/**重寫該方法枝誊,控制該視圖控制器只支持橫屏顯示
- (NSUInteger)supportedInterfaceOrientations
{
return UIInterfaceOrientationMaskLandscape;
}
*/
@end
謝謝!!!