VideoView Streaming:音频有效但视频为黑色

时间:2013-04-30 01:35:01

标签: java android android-videoview

我有一个非常奇怪的问题。我正在使用蒸汽视频,我在我的应用程序上播放,但问题是音频工作,但视频无法正常工作。它显示黑屏(参见图片以供参考)。我不知道问题是什么。音频工作正常,但视频显示黑屏。

关于问题的任何想法?

以下是我的参考代码:

public class Video_Low_Mission extends Activity {
    // Put in your Video URL here
    private String VideoURL = "rtsp://184.72.239.149/vod/mp4:BigBuckBunny_175k.mov";
    // Declare some variables
    private ProgressDialog pDialog;
    VideoView videoview;



@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    // Set the layout from video_main.xml
    setContentView(R.layout.activity_video__low__mission);
    // Find your VideoView in your video_main.xml layout
    videoview = (VideoView) findViewById(R.id.VideoView);
    // Execute StreamVideo AsyncTask
    new StreamVideo().execute();

}


// StreamVideo AsyncTask
private class StreamVideo extends AsyncTask<Void, Void, Void> {
    @Override
    protected void onPreExecute() {
        super.onPreExecute();
        // Create a progressbar
        pDialog = new ProgressDialog(Video_Low_Mission.this);
        // Set progressbar title
        pDialog.setTitle("Mission TV (Low Quality)");
        // Set progressbar message
        pDialog.setMessage("Buffering...");
        pDialog.setIndeterminate(false);
        // Show progressbar
        pDialog.show();

    }

    @Override
    protected Void doInBackground(Void... params) {
        // TODO Auto-generated method stub
        return null;
    }

    @Override
    protected void onPostExecute(Void args) {

        try {
            // Start the MediaController
            MediaController mediacontroller = new MediaController(
                    Video_Low_Mission.this);
            mediacontroller.setAnchorView(videoview);
            // Get the URL from String VideoURL
            Uri video = Uri.parse(VideoURL);
            videoview.setMediaController(mediacontroller);
            videoview.setVideoURI(video);

            videoview.requestFocus();
            videoview.setOnPreparedListener(new OnPreparedListener() {
                // Close the progress bar and play the video
                public void onPrepared(MediaPlayer mp) {
                    pDialog.dismiss();
                    videoview.start();
                }
            });
        } catch (Exception e) {
            pDialog.dismiss();

            // Error Here

            Log.e("Error", e.getMessage());
            e.printStackTrace();
        }

    }

}

// Not using options menu for this tutorial
@Override
public boolean onCreateOptionsMenu(Menu menu) {
    getMenuInflater().inflate(R.menu.video__low__mission, menu);
    return true;
}

XML:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent" >

    <VideoView
        android:id="@+id/VideoView"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:layout_centerHorizontal="true"
        android:layout_centerVertical="true" />

</RelativeLayout>

谢谢:)

3 个答案:

答案 0 :(得分:0)

android不支持播放mov文件。 mov是一种苹果格式,android中没有默认的视频编解码器来播放它们。 Reference

答案 1 :(得分:0)

您可以尝试vitamio框架,它支持.mov格式。另请查看此decription

答案 2 :(得分:0)

我使用以下代码解决了这个问题,希望它适合您。

videoView.setBackgroundColor(Color.TRANSPARENT);