如何获取视频完整时长和当前播放时间? [英] How to get video full duration and current playing time?

查看:63
本文介绍了如何获取视频完整时长和当前播放时间?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要使用 swift 创建一个自定义视频插件.但我不知道如何获得视频的完整持续时间和当前播放时间.在我的控制台中刚刚出现了这个输出,C.CMTime.我不确定我的代码有什么问题.

I need to create a custom video plugin using swift. But I don't know how to get video full duration and current playing time. In my console just appeared this output, C.CMTime. I'm not sure what wrong with my code.

我的代码

let url = NSBundle.mainBundle().URLForResource("Video", withExtension:"mp4")
let asset = AVURLAsset(URL:url, options:nil)
let duration: CMTime = asset.duration

println(duration)

推荐答案

您可以使用 CMTimeGetSeconds 将 CMTime 转换为秒.

You can use CMTimeGetSeconds to converts a CMTime to seconds.

let durationTime = CMTimeGetSeconds(duration)

这篇关于如何获取视频完整时长和当前播放时间?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆