如何在Android中显示videoview的时间 [英] How to Display time of videoview in android

查看:419
本文介绍了如何在Android中显示videoview的时间的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个用于播放视频的VideoView和它的MediaControler

I have a VideoView for Play Video and MediaControler for it

我想要在textview中显示视频的时间并根据视频的时间进行更改

I want Display time of video in textview and change it per time of video

我将这段代码用于播放视频:

I use this code for Playing video :

private void play(String uri) {
    _player.setVisibility(View.VISIBLE);
    _player.setVideoURI(Uri.parse(uri));
    MediaController mc = new MediaController(this);
    _player.setMediaController(mc);
    _player.start();

    Display display = getWindowManager().getDefaultDisplay();
    int width = display.getWidth();
    int height = display.getHeight();

    _player.setLayoutParams(new FrameLayout.LayoutParams(width, width));


}

推荐答案

此方法用于将毫秒转换为时间,_player.getDuration()用于Prepare.

this method used for convert msec to time and _player.getDuration() is used on Prepare.

    public String milliSecondsToTimer(long milliseconds) {
    String finalTimerString = "";
    String secondsString = "";

    // Convert total duration into time
    int hours = (int) (milliseconds / (1000 * 60 * 60));
    int minutes = (int) (milliseconds % (1000 * 60 * 60)) / (1000 * 60);
    int seconds = (int) ((milliseconds % (1000 * 60 * 60)) % (1000 * 60) / 1000);
    // Add hours if there
    if (hours > 0) {
        finalTimerString = hours + ":";
    }

    // Prepending 0 to seconds if it is one digit
    if (seconds < 10) {
        secondsString = "0" + seconds;
    } else {
        secondsString = "" + seconds;
    }

    finalTimerString = finalTimerString + minutes + ":" + secondsString;

    // return timer string
    return finalTimerString;
}

这篇关于如何在Android中显示videoview的时间的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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