与AVPlayer支持兼容的免费托管视频平台

问题描述 投票:0回答:1

我想在点击按钮时尝试从iOS应用播放视频,但是我想知道如何(在哪里)托管视频(免费),以便可以使用URL在AVPlayer中播放视频。我尝试将视频托管在youtube上,并将AVPlayer URL设置为youtube视频URL,但是播放器会永久加载。我包括了我的代码,它可以正常工作,我只需要知道可以在哪里上传视频以获取正确的URL。

@IBAction func didTapPlayButton(_ sender: UIButton) {
        guard let url = URL(string: "") else {
            return
        }
        // Create an AVPlayer, passing it the HTTP Live Streaming URL.
        let player = AVPlayer(url: url)

        // Create a new AVPlayerViewController and pass it a reference to the player.
        let controller = AVPlayerViewController()
        controller.player = player

        // Modally present the player and call the player's play() method when complete.
        present(controller, animated: true) {
            player.play()
        }
    }
ios swift xcode avplayer
1个回答
0
投票

您需要将视频作为二进制文件托管和提供。您可以使用对象存储区(例如Firebase StorageAWS S3)或通过网络API提供文件。只需设置正确的Content-Type(例如“ video / mp4”以帮助播放器识别二进制文件类型)

然后您可以使用视频的网址启动AVPlayer

请注意,Firebase Storage具有非常宽敞的免费层,您可能只需要它。

例如:

您可以看一下此视频文件:https://file-examples.com/wp-content/uploads/2017/04/file_example_MP4_480_1_5MG.mp4

此文件以二进制形式托管,并且内容类型设置为video / mp4。

尝试使用上述URL初始化您的AVPlayer并查看它是否有效。

© www.soinside.com 2019 - 2024. All rights reserved.