---
# System prepended metadata

title: 取得影片時間
tags: [實作相關]

---

取得影片時間
===


```java=
File videoFile = new File(VIDEO 的 FILEPATH);
```

```java=
MediaMetadataRetriever retriever = new MediaMetadataRetriever();

//use one of overloaded setDataSource() functions to set your data source
retriever.setDataSource(context, Uri.fromFile(videoFile));
String time = retriever.extractMetadata(MediaMetadataRetriever.METADATA_KEY_DURATION);
long timeInMillisec = Long.parseLong(time );

retriever.release()
```

## Ref.
[How to get duration of a video file?](https://stackoverflow.com/questions/3936396/how-to-get-duration-of-a-video-file/33247728)

###### tags: `實作相關`