【发布时间】:2015-02-23 05:47:22
【问题描述】:
我正在尝试解析包含视频网址和标题的 JSON 数据。解析数据后,我在 UITableviewCell 中显示视频缩略图。问题是当数据被解析时,当它请求缩略图时,NSNotification 选择器方法永远不会被调用。这是我的代码:
override func viewDidLoad() {
super.viewDidLoad()
getJson_results()
}
override func viewWillDisappear(animated: Bool) {
NSNotificationCenter.defaultCenter().removeObserver(self)
}
func videoThumbnailIsAvailable(notification: NSNotification) {
println("Flag1") //the control never reaches here
var thumbnail = notification.userInfo?[MPMoviePlayerThumbnailImageKey] as UIImage
self.temp_image = thumbnail
}
func videodurationIsAvailable(notification: NSNotification) {
var val = moviePlayer?.duration
self.temp_duration = val!
}
override func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return length_array;
}
override func numberOfSectionsInTableView(tableView: UITableView) -> Int {
return 1
}
override func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCellWithIdentifier("Cell", forIndexPath: indexPath) as WPR_Main
cell.imgView?.image = get_Media_thumbnail(NSURL(string:self.url[indexPath.row])!)
cell.titleLabel?.text = self.titles[indexPath.row]
return cell
}
func get_Media_thumbnail(url: NSURL) -> UIImage {
moviePlayer? = MPMoviePlayerController(contentURL: url)
NSNotificationCenter.defaultCenter().addObserver(self,
selector: "videoThumbnailIsAvailable:",
name: MPMoviePlayerThumbnailImageRequestDidFinishNotification,
object: nil)
moviePlayer?.requestThumbnailImagesAtTimes([1.0], timeOption:.NearestKeyFrame )
return self.temp_image
}
【问题讨论】: