从网址播放视频,无需扩展swift

时间:2018-04-19 11:22:51

标签: swift xcode

我想从服务的url返回播放视频,url没有扩展名,所以它不起作用。我该怎么办?

xcode9 swift 4

import AVKit
import AVFoundation
import MediaPlayer
import AudioToolbox

class ViewController: UIViewController {
    @IBOutlet weak var player_View: UIView!

   let videoURL = URL(string: "http://45.58.42.105:82/Handlers/ImageHandler.ashx?fileReference=67f0dce7-a5f5-4894-a8fd-5996f135626c");


    var playerVC = AVPlayerViewController()
    var playerView = AVPlayer()
    var urlStr = "";

    override func viewDidLoad() {
        super.viewDidLoad()
        self.playVideo();
    }

    func playVideo() {
        self.playerView = AVPlayer(url: videoURL!)
        self.playerVC.player = playerView
        self.player_View.addSubview(self.playerVC.view)
        playerVC.view.frame = self.player_View.frame
        playerView.play()
    }
}                               

0 个答案:

没有答案