播放视频Swift IOS 8

时间:2015-07-03 09:01:15

标签: ios swift

我正在使用此代码在

中播放视频
Map

然而,这似乎不适用于我的手机(IOS 8.4)可能会出现什么问题?

2 个答案:

答案 0 :(得分:2)

因为在你启动播放器之前,你要传递给avPlayerLayer,它应该是那样的

dispatch_async(dispatch_get_main_queue(), { () -> Void in
            self.activityIndicator.stopAnimating()
            var url:NSURL = NSURL(string: self.WinVideos[0].url)!
            println(self.WinVideos[0].url)
            var player:AVPlayer!
            var playerItem:AVPlayerItem!;
            player = AVPlayer(URL: url)
            var avPlayerLayer:AVPlayerLayer = AVPlayerLayer(player: player)
            avPlayerLayer.frame = CGRect(x: 20, y: 100, width: 480, height: 480)
            self.view.layer.addSublayer(avPlayerLayer)
            player.play()
  })

答案 1 :(得分:0)

我正在播放来自UIImagePickerController的视频,如下所示:

        urlVideo = info.objectForKey(UIImagePickerControllerMediaURL) as NSURL

        objMoviePlayerController = MPMoviePlayerController(contentURL: urlVideo)
        objMoviePlayerController.movieSourceType = MPMovieSourceType.Unknown
        objMoviePlayerController.view.frame = self.view.bounds
        objMoviePlayerController.scalingMode = MPMovieScalingMode.AspectFill
        objMoviePlayerController.controlStyle = MPMovieControlStyle.Fullscreen
        objMoviePlayerController.shouldAutoplay = true

        self.view.addSubview(objMoviePlayerController.view)

        objMoviePlayerController.prepareToPlay()
        objMoviePlayerController.play()