【发布时间】:2015-10-13 20:47:09
【问题描述】:
[已解决] 您好,我的应用程序曾经加载和播放视频没有任何问题,当我更新到 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 [Dictionary] 与一项 NSAllowsArbitraryLoads [布尔] = YES)
这对我有用,现在一切都恢复正常 =)
【问题讨论】:
标签: ios xcode swift video avplayer