【问题标题】:Free hosting video platform compatible with AVPlayer support兼容 AVPlayer 支持的免费托管视频平台
【发布时间】:2020-04-10 20:06:48
【问题描述】:

我试图在点击按钮时从我的 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()
        }
    }

【问题讨论】:

  • 确实,如果您提供指向电影文件(例如 .mp4)的 URL,您发布的代码似乎可以正常工作。由于典型的 youtube URL 返回整个 HTML 页面,因此您不能轻松地使用 AVPlayer 播放 YouTube 视频。相反,有一个官方图书馆可以帮助您:github.com/youtube/youtube-ios-player-helper 如果您只是在寻找可以免费托管视频的服务建议,我不确定这个社区是否是最合适的地方:)
  • 谢谢,您提出的解决方案是可行的,但由于我打算将我的应用上传到商店,我不确定它有多“合法”,所以我选择了下面的 Matan 解决方案。跨度>

标签: ios swift xcode avplayer


【解决方案1】:

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

然后您可以使用视频的 URL 发起您的 AVPlayer

请注意,Firebase 存储有一个非常慷慨的免费层,它可能就是您所需要的。

例如:

你可以看看这个视频文件: https://file-examples.com/wp-content/uploads/2017/04/file_example_MP4_480_1_5MG.mp4

此文件以二进制形式托管,并且 Content-Type 设置为 video/mp4。

尝试使用上述 URL 启动您的 AVPlayer 并查看它是否有效。

【讨论】:

猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2012-03-06
  • 1970-01-01
  • 1970-01-01
  • 2014-09-05
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多