简体   繁体   中英

Android Media Duration returns wrong value

I have set up my app using these:

https://github.com/googlesamples/android-UniversalMusicPlayer/blob/master/mobile/src/main/java/com/example/android/uamp/ui/FullScreenPlayerActivity.java

https://gist.github.com/ianhanniballake/15dce0b233b4f4b23ef8

The duration is displayed as 10, which I believe is because dividing 10000 in putLong(MediaMetadataCompat.METADATA_KEY_DURATION, 10000); by 1000 in mEnd.setText(DateUtils.formatElapsedTime(duration/1000)); to get seconds format. But why 10000?

How do I get the original duration of the track being played?

长时间通常以毫秒为单位,因此您应该除以1,000(而不是10,000)来获得秒数。

Ok, the problem was instead of 10000, I should have returned the media duration from the service itself. like player.getDuration() 10000 was (i guess) just an example by ianhanniballake

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM