单个Android活动中的多个视频视图

时间:2013-11-08 15:43:43

标签: android

我正在开发一个应用程序,其中一个屏幕需要4个videoviewa,视图就像一个屏幕上的四个sqaure框 我在一项活动中拍摄了4次视频 这是代码

vid1 = (VideoView) mView.findViewById(R.id.vid1);
        vid2 = (VideoView) mView.findViewById(R.id.vid2);
        vid3 = (VideoView) mView.findViewById(R.id.vid3);
        vid4 = (VideoView) mView.findViewById(R.id.vid4);

private void PlayVideo() {
        lnrVideoPlayback.setVisibility(View.VISIBLE);
        Thread t1 = null, t2 = null, t3 = null, t4 = null;
        if (prefsVideo.getString("v1URI", null) != null) {

            vid1.setVideoURI(Uri.parse(prefsVideo.getString("v1URI", null)));
//          vid1.setLayoutParams(new LinearLayout.LayoutParams(getResources()
//                  .getDimensionPixelSize(R.dimen.boxviewheight),
//                  getResources().getDimensionPixelSize(R.dimen.boxviewheight)));

            vid1.setVisibility(View.VISIBLE);
            t1 = new Thread(new Runnable() {

                @Override
                public void run() {
                    android.os.Process
                            .setThreadPriority(android.os.Process.THREAD_PRIORITY_URGENT_DISPLAY);

                    vid1.start();

                }
            });
        }
        if (prefsVideo.getString("v2URI", null) != null) {
            vid2.setVideoURI(Uri.parse(prefsVideo.getString("v2URI", null)));
            vid2.setMediaController(new MediaController(getActivity()));
            vid2.setVisibility(View.VISIBLE);
            t2 = new Thread(new Runnable() {

                @Override
                public void run() {
                    android.os.Process
                            .setThreadPriority(android.os.Process.THREAD_PRIORITY_URGENT_DISPLAY);
                    vid2.start();
                }
            });
        }
        if (prefsVideo.getString("v3URI", null) != null) {
            vid3.setVideoURI(Uri.parse(prefsVideo.getString("v3URI", null)));
            vid3.setMediaController(new MediaController(getActivity()));
            vid3.setVisibility(View.VISIBLE);
            t3 = new Thread(new Runnable() {

                @Override
                public void run() {
                    android.os.Process
                            .setThreadPriority(android.os.Process.THREAD_PRIORITY_URGENT_DISPLAY);
                    vid3.start();
                }
            });
        }
        if (prefsVideo.getString("v4URI", null) != null) {
            vid4.setVideoURI(Uri.parse(prefsVideo.getString("v4URI", null)));
            vid4.setMediaController(new MediaController(getActivity()));
            vid4.setVisibility(View.VISIBLE);
            t4 = new Thread(new Runnable() {

                @Override
                public void run() {
                    android.os.Process
                            .setThreadPriority(android.os.Process.THREAD_PRIORITY_URGENT_DISPLAY);

                    vid4.start();
                }
            });
        }

        t1.start();
        t2.start();
        t3.start();
        t4.start();

    }

当我播放单个视频而不是正确播放时,当我一起播放4个视频时,它会在所有4个视频中显示“视频无法播放”消息

1 个答案:

答案 0 :(得分:1)

这取决于您设备的系统/框架实现。

  1. 允许同时使用的媒体播放器实例的最大数量
  2. 允许同时使用的最大视频表面数
  3. 通常情况下,这个数字是2。