【发布时间】:2020-05-19 17:25:57
【问题描述】:
我的应用程序使用 AVPlayer 播放我的视频,但它们并非每次都播放。我只是在某些视频上出现黑屏。但是,不播放的视频每次都不相同。我不明白为什么前一分钟有效,而下一分钟却无效。我正在使用HCVimeoVideoExtractor 从 Vimeo 中提取视频。
import UIKit
import HCVimeoVideoExtractor
import Foundation
import AVKit
import AVFoundation
class Arms : UITableViewController{
@IBOutlet var Tableview: UITableView!
//video outlet
let playerController = AVPlayerViewController()
//@IBOutlet var mypic: UIImageView!
let sectionName = ["Day 0","Day 1","Day 2","Day 3","Day 4","Day 5","Day 6","7"]
let foodTitleArray = ["1 and a Half Cable Bicep Curl", "Barbell Bicep Curls", "Cable Bicep Curl","Dumbbell Bicep Curl","Bench Press Close Grip","Across The Body Tricep Extension","EZ Bar Curl", "Dumbbell Hammer Curl", "Low Pulley Cable Curl", "Preacher Curl Machine", "Skull Crusher", "Straight Bar Tricep Extension", "Rope Tricep Extension"]
let foodImageArray = ["Bicep Curl 1 and half Cable", "Bicep Curl Barbell", "Bicep Curl Cable","Bicep Curl Dumbbell","Close Grip Bench Press","Cross body tricep extension","EZ Bar Curl", "Hammer Curl Dumbbell", "Low Cable Pulley Curl", "Preacher Curl Machine", "Skull Crusher", "Tricep extension Cable", "Tricep Extension rope"]
var rowselected = Int()
//-----vids-----
//video links
var calledVideo: String?
let vids = ["https://vimeo.com/12345","https://vimeo.com/12345","https://vimeo.com/12345","https://vimeo.com/12345","https://vimeo.com/12345","https://vimeo.com/12345","https://vimeo.com/12345","https://vimeo.com/12345","https://vimeo.com/12345","https://vimeo.com/12345", "https://vimeo.com/12345", "https://vimeo.com/12345", "https://vimeo.com/12345"]
//-----vids-----
override func viewDidLoad() {
super.viewDidLoad()
}
@IBAction func Back(_ sender: Any) {
NotificationCenter.default.removeObserver(self)
self.dismiss(animated: true, completion: nil)
}
//setting up tableview rows
override func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
//return sectionName.count
return foodTitleArray.count
}
//what cell is & how it looks
override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell = Tableview.dequeueReusableCell(withIdentifier: "cellarms") as! UITableViewCell1
// cell.foodImage.image = UIImage(named: foodImageArray[indexPath.row] + ".jpg") //this is origionally how memory images are used added to cell. this way caches the images building memory.
cell.foodTitle.text = foodTitleArray[indexPath.row] //this is how to the uitableviews titles are added to cells
//shows the images in cells without storing image in cache
let bundlePath = Bundle.main.path(forResource: foodImageArray[indexPath.row], ofType: "jpg")
let image = UIImage(contentsOfFile: bundlePath!)
cell.foodImage.image = image
return (cell)
}
override func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
rowselected = indexPath.row
//indexpath.row is the code to get a number of the row selected this number then is selected from vids array and sets calledvideo to this number.
print(indexPath.row)
let number = indexPath.row
calledVideo = vids[number]
print(calledVideo)
geturl()
//making desleected row not highlighted
tableView.deselectRow(at: indexPath, animated: true)
}
//Getting url info for video by using exractor
func geturl() {
if let url = URL(string: calledVideo!) {
HCVimeoVideoExtractor.fetchVideoURLFrom(url: url, completion: { ( video:HCVimeoVideo?, error:Error?) -> Void in
if let err = error {
DispatchQueue.main.async() {
let alert = UIAlertController(title: "Error", message: err.localizedDescription, preferredStyle: .alert)
alert.addAction(UIAlertAction(title: "OK", style: .default, handler: nil))
self.present(alert, animated: true, completion: nil)
}
return
}
guard let vid = video else {
print("Invalid video object")
return
}
//play video
let player = AVPlayer(url: vid.videoURL[.Quality360p]!)
self.playerController.player = player
self.present(self.playerController, animated: true) {
player.play()
}
})
}
}
}
它是一个不同的视频,每次我都被取消。它似乎是完全随机的。以下是我在取消视频时发生的错误示例:
Domain=NSURLErrorDomain Code=-999 "cancelled" UserInfo={NSErrorFailingURLStringKey=https://gcs-vimeo.akamaized.net/exp=1581445783~acl=%2Fvimeo-prod-skyfire-std-us%2F01%2F3120%2F14%2F365604762%2F1507711789.mp4~hmac=ac26b711525132b93ce5b4c33db5f04efc84feab53f3c07ec324d15962a9f5dd/vimeo-prod-skyfire-std-us/01/3120/14/365604762/1507711789.mp4?source=1, NSErrorFailingURLKey=https://gcs-vimeo.akamaized.net/exp=1581445783~acl=%2Fvimeo-prod-skyfire-std-us%2F01%2F3120%2F14%2F365604762%2F1507711789.mp4~hmac=ac26b711525132b93ce5b4c33db5f04efc84feab53f3c07ec324d15962a9f5dd/vimeo-prod-skyfire-std-us/01/3120/14/365604762/1507711789.mp4?source=1, _NSURLErrorRelatedURLSessionTaskErrorKey=(
"LocalDataTask <A7D7517F-1F77-495B-80A1-2F61FE5B723D>.<1>"
), _NSURLErrorFailingURLSessionTaskErrorKey=LocalDataTask <A7D7517F-1F77-495B-80A1-2F61FE5B723D>.<1>, NSLocalizedDescription=cancelled} [-999]
【问题讨论】: