0

我有一个歌曲列表,并希望将当前正在播放的歌曲的背景颜色与搜索栏或进度条一样。当我的歌曲完成并进入下一首歌曲时,它应该能够提升背景颜色。请提供任何想法或源代码如何实现此功能。提前感谢您的帮助。

4

1 回答 1

0

The main idea is to take song length in milliseconds and use it as 100% of progress bar.

MediaPlayer allows you to do that:

public long getSoundDuration(Context context, String file){

    AssetFileDescriptor afd;
    try {
        afd = context.getAssets().openFd(file);
        MediaPlayer player = new MediaPlayer();

        player.setDataSource(afd.getFileDescriptor(),afd.getStartOffset(),afd.getLength());

        player.prepare();

        int duration = player.getDuration();
        player.release();
        return duration;
    } catch (IOException e) {
        e.printStackTrace();
    }

    return 0; 
}

So now when you have duration, its easy to convert to progress bar value.

Hope it will help you

于 2013-09-08T08:00:21.177 回答