找到你要的答案

Q:Video plays from browser but not on Movie player -SWIFT

Q:视频播放从浏览器,但不是在电影播放器-斯威夫特

Tired of posting questions on SO about the same problem and still not getting solution..If anyone solves this i am gonna award bounty to user afterwards.

I am trying to play video that is on server.A video from the Url(which is commented) gets played but the other dont.What am i doing wrong??

class VideoViewController: UIViewController {

    var moviePlayer:MPMoviePlayerController!

    override func viewDidLoad() {

        super.viewDidLoad()

    }

    override func viewDidAppear(animated: Bool) {

        //var url = NSURL(string: "http://devimages.apple.com/iphone/samples/bipbop/gear1/prog_index.m3u8")
        //playVideoFromURL(url!)

        var url = NSURL(string: "private url")
        playVideoFromURL(url!)

    }

    func playVideoFromURL( address: NSURL ) {

        println(address)
        var playerVC = MPMoviePlayerViewController(contentURL: address)
        playerVC.modalTransitionStyle = UIModalTransitionStyle.CoverVertical
        self.presentViewController(playerVC, animated: false, completion: nil)
        playerVC.moviePlayer.prepareToPlay()
        playerVC.moviePlayer.play()


    }
}

Movie player plays the video of the commented ones but doesnot plays the other.What may be the reason for this?

厌倦了张贴关于同样的问题,仍然没有得到解决的问题..如果有人解决这个问题,我会奖励赏金后,用户。

我试图播放的视频是在服务器上。一个视频从URL(这是评论)得到发挥,但另一个不。我做错了什么??

class VideoViewController: UIViewController {

    var moviePlayer:MPMoviePlayerController!

    override func viewDidLoad() {

        super.viewDidLoad()

    }

    override func viewDidAppear(animated: Bool) {

        //var url = NSURL(string: "http://devimages.apple.com/iphone/samples/bipbop/gear1/prog_index.m3u8")
        //playVideoFromURL(url!)

        var url = NSURL(string: "private url")
        playVideoFromURL(url!)

    }

    func playVideoFromURL( address: NSURL ) {

        println(address)
        var playerVC = MPMoviePlayerViewController(contentURL: address)
        playerVC.modalTransitionStyle = UIModalTransitionStyle.CoverVertical
        self.presentViewController(playerVC, animated: false, completion: nil)
        playerVC.moviePlayer.prepareToPlay()
        playerVC.moviePlayer.play()


    }
}

电影播放器播放的评论的但是不起到其他视频。是什么原因?

answer1: 回答1:

Your code is correct. All you need is to update your info.plist file by adding this key:

<key>NSAppTransportSecurity</key>  
<dict>  
     <key>NSAllowsArbitraryLoads</key><true/>  
</dict>

Or you can add it another way and it will look like:

你的代码是正确的。所有你需要的是通过添加这一关键更新你的Info.plist文件:

<key>NSAppTransportSecurity</key>  
<dict>  
     <key>NSAllowsArbitraryLoads</key><true/>  
</dict>

或者你可以添加它的另一种方式,它会看起来像:

ios  swift  video  mpmovieplayercontroller  mpmovieplayer