简体   繁体   English

我在 Google Photos API 中找不到如何获取视频时长。 有什么线索吗?

[英]I can't find how to get video duration in Google Photos API. Any clue?

The Google Photos library API does not return the duration of a video. Google 相册库 API 不返回视频的时长。 API provides a lot of misc information like camera model and other stuff, but missing very basic things, like video duration, archive status and file size API 提供了很多杂项信息,例如相机 model 和其他内容,但缺少非常基本的信息,例如视频持续时间、存档状态和文件大小

If you have access to the file uri you could try something like this:如果您有权访问文件 uri,则可以尝试以下操作:

Android | Android | Kotlin Kotlin

fun getFileDuration(context: Context, uri: Uri): Int {
    try {
        val metadataRetriever = MediaMetadataRetriever()
        metadataRetriever.setDataSource(context, uri)
        val durationStr = metadataRetriever.extractMetadata(MediaMetadataRetriever.METADATA_KEY_DURATION)
        if (durationStr != null) return Integer.parseInt(durationStr)
    } catch (e: Exception) {
        e.printStackTrace()
        Log.w("getFileDuration", "Error getting duration of file with uri $uri with ${e.message}")
    }
    return 0
}

iOS | iOS | Swift Swift

func getFileDuration(_ uri: URL) -> Int {
    let asset = AVURLAsset(url: uri)
    let audioDuration = asset.duration.seconds * 1000
    return Int(audioDuration)
}

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 我的Braintree有一个PaymentMethodNonce字符串,但是我似乎在服务器端找不到它。 有任何线索吗? - I got a PaymentMethodNonce string with Braintree, but I can't seem to find it on the server side. Any Clue? 我不知道为什么这行不通(SWIFT) - I can't get any clue why this doesn't work out (SWIFT) Xcode/iOS - 尝试通过简单的打印进行控制台调试,但无法正常工作。 不知道如何找到问题 - Xcode/iOS - Trying a simple print to console debug, can't get it to work. No clue how to find the issue 由于已弃用 UIWebView API,无法在 Appstore 上发布。如何正确迁移到 WKWebView? - Can't publish on Appstore because of the deprecated UIWebView API. How can I migrate to WKWebView correctly? 无法从天气API获取json。 的iOS - Can't get json from weather api. iOS 如何使用Google Map API在iOS中获取当前位置? - How to get the current location in iOS using google map api.? 如何从API访问文本响应。 迅速地? - How can I access the text response from API. in swift? 我可以将视频剪辑/编辑功能用作iOS相册应用吗? - Can I get video clip/edit function as iOS Photos app? 如何使用Photos Foundation在iOS系统库中获取视频? - How can I get a video'url in iOS system gallery using Photos Foundation? iOS-如何使用FBGraph API从我的应用程序“赞/共享”特定页面的任何照片? - iOS - How can I “Like/Share” any Photos of particular Page from my App with FBGraph API?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM