用我的代码,我试图在登录屏幕上播放视频。我已经导入了mp4视频文件。但是,当我运行此代码视频时,它不会出现在屏幕上。实际上该视频文件显示为??标志 。我需要添加其他任何东西来播放视频吗?请帮助
<VideoView
android:id="@+id/videoView1"
android:layout_width="match_parent"
android:layout_height="match_parent"
/>
//下面的Java代码
public VideoView videoView;public MediaPlayer mediaPlayer;
@OnClick(R.id.email_sign_in_button)
void delegateLogin() {
progressBar.setVisibility(View.VISIBLE);
loginPresenter.doLogin(usernameInput.getText().toString(), passwordInput.getText().toString());
}
@OnClick(R.id.register_now_button)
void registerNow(){
loginPresenter.doOpenRegisterScreen(this);
}
@OnClick(R.id.forgot_password_button)
void forgotPassword(){
loginPresenter.doOpenForgotPasswordScreen(this);
}
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_login);
ButterKnife.bind(this);
videoView=(VideoView)findViewById(R.id.videoView1);
Uri uri= Uri.parse("android.resource://"
+getPackageName()
+"/"
+R.raw.mt_launch_screen);
videoView.setVideoURI(uri);
// videoView.requestFocus();
videoView.start();
videoView.setOnPreparedListener(new MediaPlayer.OnPreparedListener() {
@Override
public void onPrepared(MediaPlayer mediaPlayer) {
mediaPlayer.setLooping(true);
// mediaPlayer.start();
}
});
查看Android的文档:https://developer.android.com/guide/topics/media/mediaplayer#java
您需要使用MediaPlayer
中的onCreate
做一些事情>
Uri uri= Uri.parse("android.resource://"
+getPackageName()
+"/"
+R.raw.mt_launch_screen);
mediaPlayer = MediaPlayer.create(context, uri);
mediaPlayer.start(); // no need to call prepare(); create() does that for you