iOS簡單的視頻播放

fb24 9年前發布 | 1K 次閱讀 Objective-C IOS

導入 MediaPlayer.framework

- (void)viewDidLoad
{
    [super viewDidLoad];

NSString* path = [[NSBundle mainBundle] pathForResource:@"test1" ofType:@"mp4"];
NSURL* url = [NSURL fileURLWithPath:path];
_playerController = [[MPMoviePlayerViewController alloc] initWithContentURL:url];

UIButton* button = [UIButton buttonWithType:UIButtonTypeRoundedRect];
button.frame = CGRectMake(100, 100, 100, 40);
button.backgroundColor = [UIColor redColor];
[button addTarget:self action:@selector(play) forControlEvents:UIControlEventTouchUpInside];
[self.view addSubview:button];

}

  • (void)play{ [self presentMoviePlayerViewControllerAnimated:_playerController]; //播放 [_playerController.moviePlayer play]; }</pre>
 本文由用戶 fb24 自行上傳分享,僅供網友學習交流。所有權歸原作者,若您的權利被侵害,請聯系管理員。
 轉載本站原創文章,請注明出處,并保留原始鏈接、圖片水印。
 本站是一個以用戶分享為主的開源技術平臺,歡迎各類分享!