如何在活动启动时使MediaController可见

时间:2016-05-07 15:09:50

标签: android user-interface

这是我的代码:

protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_test_video_view);
    VideoView vv = (VideoView) findViewById(R.id.player);
    MediaController mc = new MediaController(this);
    mc.setVisibility(View.VISIBLE);
    vv.setMediaController(mc);
    vv.setVideoPath("/sdcard/Downloads/test.mp4");
    vv.seekTo(100);
}

mediacontroller没有显示,但是当我点击videoview时,mediacontroller显示如下:

enter image description here

如何在活动启动时看到mediacontroller

1 个答案:

答案 0 :(得分:0)

我修改了它。显示位置:

package ro.rotry;

import android.media.MediaPlayer;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.widget.MediaController;
import android.widget.VideoView;

public class TestVideoView extends AppCompatActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_test_video_view);
        VideoView vv = (VideoView) findViewById(R.id.player);

        final MediaController mc = new MediaController(this);
        vv.setMediaController(mc);
        vv.setVideoPath("/sdcard/Downloads/test.mp4");
        vv.seekTo(100);
        vv.setOnPreparedListener(new MediaPlayer.OnPreparedListener() {
            @Override
            public void onPrepared(MediaPlayer mp) {
                mc.show();
            }
        });
    }
}