【问题标题】:sorry, this video cannot be played in videoview?抱歉,此视频无法在 videoview 中播放?
【发布时间】:2011-09-18 14:33:22
【问题描述】:

朋友,

我正在使用以下代码在我的应用程序中显示 mp4 视频 并面临以下问题

我在 google 和 stackoverflow 上看到了很多与此问题相关的帖子,但每个人都给出了自己的建议,没有共同的答案。

1) 我在模拟器中看不到视频 2) 在不同的手机中,有时会播放一些稀有视频,并且大部分时间会给出上述消息。

我的代码

VideoView myVideoView = (VideoView)findViewById(R.id.videoview);

      String viewSource ="http://dev.hpac.dev-site.org/sites/default/files/videos/about/mobile.mp4";

      myVideoView.setVideoURI(Uri.parse(viewSource));
      myVideoView.setMediaController(new MediaController(this));
      myVideoView.requestFocus();
      myVideoView.start();

任何人都可以指导我解决此问题的方法是什么 任何帮助将不胜感激。

【问题讨论】:

  • 我认为 .mp4 视频的编解码器有问题您是否尝试过不同 fps 和质量的视频,这有什么不同吗?
  • 请问您能否解释一下,是的,这可能是问题所在。
  • 这是什么意思?不同的 fps 和质量
  • 感谢您的网址,它帮助我测试了我的应用程序。
  • 先生。 @While-E 你的道德责任是帮助有需要的人,而不是与他们争论。任何真正需要帮助的人在这里发布他/她的问题,他/她不必在所有方面都完美无缺。所以小心亲爱的......

标签: android android-videoview


【解决方案1】:

您可以使用您的文件制作输出流并获取流的绝对路径,然后将路径放入视频视图

    private String getDataSource(String path) throws IOException {
    if (!URLUtil.isNetworkUrl(path)) {
        return path;
    } else {
        URL url = new URL(path);
        URLConnection cn = url.openConnection();
        cn.connect();
        InputStream stream = cn.getInputStream();
        if (stream == null)
            throw new RuntimeException("stream is null");
        File temp = File.createTempFile("mediaplayertmp", "dat");
        temp.deleteOnExit();
        String tempPath = temp.getAbsolutePath();
        @SuppressWarnings("resource")
        FileOutputStream out = new FileOutputStream(temp);
        byte buf[] = new byte[128];
        do {
            int numread = stream.read(buf);
            if (numread <= 0)
                break;
            out.write(buf, 0, numread);
        } while (true);
        try {
            stream.close();
        } catch (IOException ex) {
            Log.e(TAG, "error: " + ex.getMessage(), ex);
        }
        return tempPath;
    }
}

public void initVideo() {
    try {

        if (!mVideoView.isPlaying()) {

            if (url > playList.size() - 1) {
                url = 0;
            }
            String[] playurl = (playList.get(url)).split("\\.");
            String urlExtention = playurl[playurl.length - 1];

            if (urlExtention.equals("mp4")) {
                playVideo(playList.get(url));
            } else if (urlExtention.equals("jpg")
                    || urlExtention.equals("jpeg")) {

                Intent intentShedule = new Intent(Default_Player.this,
                        ImagePlayer.class);

                intentShedule.putExtra("imagePath", playList.get(url));
                intentShedule.putExtra("urlValue", url);
                intentShedule.putExtra("playlistType", playlistType);
                intentShedule.addFlags(Intent.FLAG_ACTIVITY_NO_ANIMATION);
                startActivity(intentShedule);
                finish();
            } else {
                Intent intentShedule = new Intent(Default_Player.this,
                        WebContentView.class);

                intentShedule.putExtra("webPath", playList.get(url));
                intentShedule.putExtra("urlValue", url);
                intentShedule.putExtra("playlistType", playlistType);
                intentShedule.addFlags(Intent.FLAG_ACTIVITY_NO_ANIMATION);
                startActivity(intentShedule);
                finish();
            }

        }

        mVideoView.setOnErrorListener(new MediaPlayer.OnErrorListener() {

            @Override
            public boolean onError(MediaPlayer mp, int what, int extra) {
                System.out.println("set on error listner");

                //do somthing if alert this video can not be played

                return false;
            }
        });

        mVideoView
                .setOnCompletionListener(new MediaPlayer.OnCompletionListener() {

                    public void onCompletion(MediaPlayer vmp) {

                        playnew();
                    }
                });

    } catch (Exception e) {

    }

    // TODO Auto-generated method stub

}

如果警告此视频无法播放,则在错误侦听器上使用

【讨论】:

    【解决方案2】:

    在 Eclipse 模拟器视频中未显示来自网站(互联网)的链接。 如果你想播放特定的视频。然后制作原始文件夹并给出以下路径

    String path1="android.resource://your package name/"+ R.raw.video name;

    Uri uri=Uri.parse(path1);
    videoView.setVideoURI(uri);

    【讨论】:

      猜你喜欢
      • 2013-12-04
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-12-20
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多