如何从解析服务器流式传输视频文件?

时间:2019-01-04 18:45:22

标签: ios swift video-streaming parse-server

我试图流式传输我从模拟器照片库上传到Parse服务器的视频,该视频存储为PFFile类型的.bin文件,但是不幸的是,我没有成功。有没有可行的解决方案?

过去有一些与此相关的问题/帖子,但是没有给出有效的具体答案。

import UIKit
import AVFoundation
import AVKit

class VideoCollectionViewCell: UICollectionViewCell {

var activityFeed: ActivityFeed?

var avPlayer: AVPlayer?
var avPlayerLayer: AVPlayerLayer?

lazy var playBtn: UIButton = {
    let button = UIButton(type: .system)
    button.translatesAutoresizingMaskIntoConstraints = false
    let image = UIImage(named: "play")
    button.tintColor = .white
    button.setImage(image, for: .normal)

    button.addTarget(self, action: #selector(handlePlay), for: .touchUpInside)

    return button
}()

func handlePlay() {

    if let videoFile = activityFeed?.collegeVideo {

        let videoImageUrlString = videoFile.url

    if let videoUrlString = videoImageUrlString, let url = URL(string: videoUrlString) {
            avPlayer = AVPlayer(url: url)

            avPlayerLayer = AVPlayerLayer(player: avPlayer)
            avPlayerLayer?.frame = contentView.bounds
            contentView.layer.addSublayer(avPlayerLayer!)
            avPlayer?.play()

            print("Attempting to play video.....")
        }
    }
  }
}

我希望按下播放按钮并播放视频,但是除了执行我的打印语句外,什么都没有发生。

0 个答案:

没有答案