如何打开视频并在iOS上点击按钮进行播放

时间:2016-06-01 08:56:01

标签: ios swift video

我对iOS很新,而且经验很少。 请有人可以告诉我如何编写我的应用程序,以便打开视频并按下按钮进行播放?我无法在任何地方找到如何做到这一点。任何帮助将不胜感激。

2 个答案:

答案 0 :(得分:1)

内部按钮点击事件

    let videoURL = NSURL(string: "https://clips.vorwaerts-gmbh.de/big_buck_bunny.mp4")
    let player = AVPlayer(URL: videoURL!)
    let playerLayer = AVPlayerLayer(player: player)
    playerLayer.frame = CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height)
    playerLayer.videoGravity = AVLayerVideoGravityResizeAspectFill
    self.view.layer.addSublayer(playerLayer)
    player.play()

答案 1 :(得分:-2)

我认为此代码可以帮助您打开电影播放器​​。

NSURL *movieURL = [NSURL URLWithString:@"http://example.com/somefile.mp4"];
movieController = [[MPMoviePlayerViewController alloc] initWithContentURL:movieURL];
[self presentMoviePlayerViewControllerAnimated:movieController];
[movieController.moviePlayer play];