[已解决]您好我的应用程序用于加载和播放视频没有任何问题,只要我更新到ios 9出错了。我试图让每个单元格都有自己的子视图来播放视频。
我的源代码很长,但这是我关注的部分。
在主视图控制器中:
func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell{
let cell: CustomCellTableViewCell = tableView.dequeueReusableCellWithIdentifier("cell", forIndexPath: indexPath) as! CustomCellTableViewCell
let videoURL = NSURL(string: Videos[indexPath.row].url!)
cell.moviePlayer = MPMoviePlayerController(contentURL: videoURL)
cell.moviePlayer.controlStyle = MPMovieControlStyle.None
cell.moviePlayer.scalingMode = MPMovieScalingMode.AspectFit
cell.moviePlayer.movieSourceType = MPMovieSourceType.File
cell.moviePlayer.repeatMode = MPMovieRepeatMode.One
cell.moviePlayer.initialPlaybackTime = -1.0
cell.moviePlayer.view.frame = cell.movieView.bounds
cell.moviePlayer.view.center = CGPointMake(CGRectGetMidX(cell.movieView.bounds), CGRectGetMidY(cell.movieView.bounds))
cell.moviePlayer.prepareToPlay()
cell.moviePlayer.pause()
cell.movieView.addSubview(cell.moviePlayer.view)
return cell
}
自定义单元格类中的
import UIKit
import Parse
import Bolts
import MediaPlayer
import AVKit
@available(iOS 8.0, *)
class CustomCellTableViewCell: UITableViewCell {
@IBOutlet weak var movieView: UIView!
var moviePlayer: MPMoviePlayerController!
var videoURL:NSURL!
override func awakeFromNib() {
super.awakeFromNib()
moviePlayer = MPMoviePlayerController(contentURL: videoURL)
}
override func setSelected(selected: Bool, animated: Bool) {
super.setSelected(selected, animated: animated)
// Configure the view for the selected state
}
}
这曾经在之前完美地工作,现在它正在编译而没有任何错误,但它没有显示视频,而是显示黑屏。
注意:我还改变了一件事,在构建设置中我将Bitcode设置为NO,以摆脱链接器命令失败!
**
我如何解决它--- //
所以我所要做的就是(不改变原始代码),就是为所有版本重新启用Bitcode(除了 debug)o摆脱链接器命令。在那之后,我编辑了我的 info.plist(使用一个项添加NSAppTransportSecurity [Dictonary] NSAllowsArbitraryLoads [布尔值] =是)
这对我来说,现在每件事情都恢复正常=)
答案 0 :(得分:1)
From Apple MPMoviePlayerController Docs
MPMoviePlayerController类在iOS 9中已正式弃用。 (MPMoviePlayerViewController类也正式弃用。) 要在iOS 9及更高版本中播放视频内容,请改用 AVPictureInPictureController或AVPlayerViewController类来自 AVKit框架,或WebKit的WKWebView类。
您需要切换到使用AVPlayerViewController
Link to AVPlayerViewController Docs
对于AVPlayerViewController
let videoURL = NSURL(string: Videos[indexPath.row].url!)
let player = AVPlayer(URL: videoURL)
var playerViewController = AVPlayerViewController()
playerViewController.player = player
self.presentViewController(playerViewController, animated: true) {
playerViewController.player.play()
}
仅限AVPlayer
let videoURL = NSURL(string: Videos[indexPath.row].url!)
let player = AVPlayer(URL: videoURL)
let playerLayer = AVPlayerLayer(player: player)
playerLayer.frame = cell.view.bounds
cell.view.layer.addSublayer(playerLayer)
player.play()
确保添加import AVKit
和import AVFoundation