Media Foundation 中的标准电影播放器似乎不支持非常流畅的擦洗。我想让它在您将手指滑过栏时不断刷新显示的视频,而不是像默认情况下那样每隔几秒跳一次。起初我认为默认控件可能内置了某种延迟,但使用我自己的滑块设置播放时间并没有帮助。有任何想法吗?
编辑:我还在试验,看起来可能的擦洗起点之间有一个固定的时间间隔。也许有一些方法可以减少间隔。
Media Foundation 中的标准电影播放器似乎不支持非常流畅的擦洗。我想让它在您将手指滑过栏时不断刷新显示的视频,而不是像默认情况下那样每隔几秒跳一次。起初我认为默认控件可能内置了某种延迟,但使用我自己的滑块设置播放时间并没有帮助。有任何想法吗?
编辑:我还在试验,看起来可能的擦洗起点之间有一个固定的时间间隔。也许有一些方法可以减少间隔。
这对我有用。我从幻灯片更改的视频资产中抓取一帧。请参阅下面的代码。它从我当前的项目中删除,可能包含一些错误,但你会明白的。虽然希望没问题,但它在 Swift 1 中。
var urlVideo :NSURL = NSURL()
var vidLength :CMTime = CMTime()
var durInSeconds: Float = 0.00
var timescale:CMTimeScale = CMTimeScale()
var videoInfo:NSDictionary = NSDictionary()
var chosePosSlider:UISlider = UISlider()
@IBOutlet weak var imgCont: UIImageView!
func generateThumnail(url : NSURL, fromTime:Float64) -> UIImage {
var asset :AVAsset = AVAsset.assetWithURL(url) as! AVAsset
var assetImgGenerate : AVAssetImageGenerator = AVAssetImageGenerator(asset: asset)
assetImgGenerate.appliesPreferredTrackTransform = true
assetImgGenerate.requestedTimeToleranceAfter = kCMTimeZero;
assetImgGenerate.requestedTimeToleranceBefore = kCMTimeZero;
var error : NSError? = nil
var time : CMTime = CMTimeMakeWithSeconds(fromTime, timescale)
var img : CGImageRef = assetImgGenerate.copyCGImageAtTime(time, actualTime: nil, error: &error)
var frameImg : UIImage = UIImage(CGImage: img)!
return frameImg
}
func sliderValueDidChange(sender:UISlider!) {
var newTime:Float = durInSeconds * sender.value
setFrame(newTime)
}
func setFrame(pos:Float) {
imgCont.image = generateThumnail(urlVideo, fromTime: Float64(pos))
}
func imagePickerController(picker: UIImagePickerController, didFinishPickingMediaWithInfo info: [NSObject : AnyObject]) {
self.dismissViewControllerAnimated(true, completion: nil)
videoInfo = info as NSDictionary
urlVideo = videoInfo.objectForKey(UIImagePickerControllerMediaURL) as! NSURL
var asset :AVAsset = AVAsset.assetWithURL(urlVideo) as! AVAsset
vidLength = asset.duration
durInSeconds = Float(CMTimeGetSeconds(vidLength))
timescale = vidLength.timescale
chosePosSlider = UISlider(frame:CGRectMake(20, 450, 340, 20))
chosePosSlider.minimumValue = 0
chosePosSlider.maximumValue = 1
chosePosSlider.continuous = true
chosePosSlider.tintColor = UIColor.greenColor()
chosePosSlider.value = 0
chosePosSlider.addTarget(self, action: "sliderValueDidChange:", forControlEvents: .ValueChanged)
self.view.addSubview(chosePosSlider)
setFrame(0.0)
}