如何使用远程URL在Android模拟器中播放mp4视频?我使用下面的代码,但这段代码给我错误“抱歉,这个视频无法播放”。
07-05 16:58:19.525: INFO/AwesomePlayer(34): mConnectingDataSource->connect() returned -1007 07-05 16:58:19.525: ERROR/MediaPlayer(1242): error (1, -1007) 07-05 16:58:19.525: ERROR/MediaPlayer(1242): Error (1,-1007) 07-05 16:58:19.525: DEBUG/VideoView(1242): Error: 1,-1007
我的代码是: -
public class VideoPlayerController extends Activity { @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); VideoView videoView = (VideoView) findViewById(R.id.VideoView); MediaController mediaController = new MediaController(this); mediaController.setAnchorView(videoView); String Video="http://s509.photobucket.com/albums/s338/eveanthony/?action=view¤t=Video013.mp4"; videoView.setMediaController(mediaController); videoView.setVideoURI(Uri.parse(Video)); videoView.start(); } }
答案 0 :(得分:8)
您需要在原始设备而不是模拟器上执行应用程序,因为它不支持播放视频文件。在极少数情况下,它可能会,但它实际上取决于您的系统配置。
答案 1 :(得分:2)
Android 4.1.2版似乎在youtube app中的模拟器中播放mp4视频,而不是其他地方。我测试了它。英特尔和非英特尔版本都可以使用。 4.0.3没有播放它们。
答案 2 :(得分:0)
private VideoView myVideoView;
private int position = 0;
private ProgressDialog progressDialog;
private MediaController mediaControls;
@Override
protected void onCreate(final Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
private static final String Videos_URL = "*Your_URI*";
// Get the layout from video_main.xml
setContentView(R.layout.activity_main);
// Find your VideoView in your video_main.xml layout
myVideoView = (VideoView) findViewById(R.id.videoView);
// Create a progressbar
progressDialog = new ProgressDialog(this);
// Set progressbar title
progressDialog.setTitle("Anything u Want");
// Set progressbar message
progressDialog.setMessage("Loading...");
progressDialog.setCancelable(false);
// Show progressbar
progressDialog.show();
try {
Uri video = Uri.parse(Videos_URL);
myVideoView.setVideoURI(video);
myVideoView.setMediaController(mediaControls);
} catch (Exception e) {
Log.e("Error", e.getMessage());
e.printStackTrace();
}
myVideoView.requestFocus();
myVideoView.setOnPreparedListener(new OnPreparedListener() {
// Close the progress bar and play the video
public void onPrepared(MediaPlayer mp) {
progressDialog.dismiss();
myVideoView.seekTo(position);
if (position == 0) {
myVideoView.start();
} else {
myVideoView.pause();
}
}
});
}
@Override
public void onSaveInstanceState(Bundle savedInstanceState) {
super.onSaveInstanceState(savedInstanceState);
savedInstanceState.putInt("Position", myVideoView.getCurrentPosition());
myVideoView.pause();
}
@Override
public void onRestoreInstanceState(Bundle savedInstanceState) {
super.onRestoreInstanceState(savedInstanceState);
position = savedInstanceState.getInt("Position");
myVideoView.seekTo(position);
}
}