VideoView流:音频有效,但视频为黑色 [英] VideoView Streaming: Audio works but video is black

查看:131
本文介绍了VideoView流:音频有效,但视频为黑色的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个很奇怪的问题.我正在使用蒸汽视频,并在我的应用程序上播放它,但问题是音频有效,但视频不起作用.它显示黑屏(请参阅图像以供参考.)我不知道问题是什么.音频工作正常,但视频显示黑屏.

I have a very strange issue. I am using a steam video and I play it on my app but the issue is that Audio works but video is not working. It shows a black screen (See image for reference.) I have no idea what the issue is. Audio works fine but video shows black screen.

对这个问题可能有什么想法?

Any ideas of what the issue can be?

这是我的代码供参考:

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>

谢谢:)

推荐答案

android不支持mov文件的播放. mov是Apple格式,并且android中没有默认的视频编解码器来播放它们. 参考

Playing of mov files is not supported on the android. mov is an apple format, and there is not a default video codec in android to play them. Reference

这篇关于VideoView流:音频有效,但视频为黑色的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆