我需要在我的android应用中播放此视频: “ https://storage.weacom.ru/movies/2018_02/12_WTV_zimnik_640.mp4” 但是我看到黑屏,看一下我的代码:
import android.net.Uri;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.widget.MediaController;
import android.widget.VideoView;
public class MainActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
VideoView vidView = (VideoView)findViewById(R.id.myVideo);
String vidAddress = "https://storage.weacom.ru/movies/2018_02/12_WTV_zimnik_640.mp4";
Uri vidUri = Uri.parse(vidAddress);
vidView.setVideoURI(vidUri);
MediaController vidControl = new MediaController(this);
vidControl.setAnchorView(vidView);
vidView.setMediaController(vidControl);
vidView.start();
}
}
答案 0 :(得分:1)
尝试这样:
private VideoView videoView;
videoView = (VideoView) findViewById(R.id.videoView);
Uri video = Uri.parse("Your_link");
MediaController vidControl = new MediaController(this);
videoView.setAnchorView(vidControl);
videoView.setVideoURI(video);
videoView.setOnPreparedListener(new MediaPlayer.OnPreparedListener() {
@Override
public void onPrepared(MediaPlayer mp) {
mp.setLooping(true);
videoView.start();
}
});
希望这会有所帮助。
答案 1 :(得分:0)
尝试:
import android.app.ProgressDialog;
import android.graphics.PixelFormat;
import android.media.MediaPlayer;
import android.net.Uri;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.widget.MediaController;
import android.widget.VideoView;
public class MainActivity extends AppCompatActivity {
VideoView vidView;
ProgressDialog dialog;
MediaController controller;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
try {
vidView = (VideoView) findViewById(R.id.myVideo);
dialog = ProgressDialog.show(MainActivity.this, "wait", "Buffering
video...", false);
dialog.setCancelable(true);
getWindow().setFormat(PixelFormat.TRANSLUCENT);
controller = new MediaController(MainActivity.this);
String vidAddress = "https://storage.weacom.ru/movies/2018_02/12_WTV_zimnik_640.mp4";
Uri vidUri = Uri.parse(vidAddress);
vidView.setMediaController(controller);
vidView.setVideoURI(vidUri);
vidView.setOnPreparedListener(new MediaPlayer.OnPreparedListener() {
public void onPrepared(MediaPlayer mp) {
dialog.dismiss();
vidView.start();
}
});
}
catch (Exception e) {
dialog.dismiss();
}
}
}
如果看到“无法播放此视频”,请更改视频格式...