【问题标题】:Embedding a local video into a UIView将本地视频嵌入到 UIView
【发布时间】:2018-02-03 19:00:26
【问题描述】:

如何将本地视频嵌入到 UIView 中?

这里有一个类似的问题:Embeding youtube video into a UIView/UIWebView 但是,它在 obj-c 中并使用 youtube。

【问题讨论】:

    标签: ios swift uiview youtube


    【解决方案1】:

    你可以使用 AVPlayer

    import UIKit
    import AVFoundation
    import AVKit
    
    class ViewController: UIViewController {
    
        var avPlayer: AVPlayer!
    
        override func viewDidLoad() {
    
            super.viewDidLoad()
            let filepath: String? = Bundle.main.path(forResource: "qidong", ofType: "mp4")
            let fileURL = URL.init(fileURLWithPath: filepath!)
    
    
            avPlayer = AVPlayer(url: fileURL)
    
    
            let avPlayerController = AVPlayerViewController()
            avPlayerController.player = avPlayer
            avPlayerController.view.frame = CGRect(x: 0, y: 0, width: UIScreen.main.bounds.size.width, height: UIScreen.main.bounds.size.height)
    
    //  hide show control
            avPlayerController.showsPlaybackControls = false
    // play video
    
            avPlayerController.player?.play()
            self.view.addSubview(avPlayerController.view)
        }
    }
    

    【讨论】:

    • 抱歉,我想在 UIVIEW 中播放视频
    • 这就是所谓的'vidview'"
    • 我想在没有控件的情况下播放它
    • 谢谢你,先生,(我来自开罗的 akhi ;))!
    猜你喜欢
    • 2013-01-19
    • 2015-03-18
    • 2011-07-04
    • 1970-01-01
    • 2013-12-24
    • 2018-06-11
    • 1970-01-01
    • 1970-01-01
    • 2017-10-06
    相关资源
    最近更新 更多