I didn't use a real device, I was working on emulator. (Problem Solved)
我正在开发直播视频应用程序。我有很多直播网址,其中包含* .m3u8后缀。
当我启动应用程序时,我只能听到声音,但没有视频显示。视频显示区域总是很暗。
我正在等待你的有用建议来解决我的问题。
问候。
我的一些代码:
public class MainActivity extends Activity {
private static ProgressDialog progressDialog;
String videourl = "URL/playlist.m3u8";
VideoView videoView;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
videoView = (VideoView) findViewById(R.id.video_View);
progressDialog = ProgressDialog.show(MainActivity.this, "", "Buffering video...", true);
progressDialog.setCancelable(false);
PlayVideo();
}
private void PlayVideo() {
try {
getWindow().setFormat(PixelFormat.TRANSLUCENT);
MediaController mediaController = new MediaController(MainActivity.this);
mediaController.setAnchorView(videoView);
Uri video = Uri.parse(videourl);
videoView.setMediaController(mediaController);
videoView.setVideoURI(video);
videoView.requestFocus();
videoView.setVisibility(View.VISIBLE);
videoView.setOnPreparedListener(new OnPreparedListener() {
public void onPrepared(MediaPlayer mp) {
progressDialog.dismiss();
videoView.start();
}
});
} catch (Exception e) {
progressDialog.dismiss();
System.out.println("Video Play Error :" + e.toString());
finish();
}
}
}
布局:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<VideoView
android:id="@+id/video_View"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
</VideoView>
</LinearLayout>