简体   繁体   English

抱歉,此视频无法在 videoview 中播放?

[英]sorry, this video cannot be played in videoview?

freinds,朋友们,

i am using following code to display a mp4 video in my application and facing following problems我正在使用以下代码在我的应用程序中显示 mp4 视频并面临以下问题

i have seen so many posts related to this issue on google and stackoverflow but every one giving his own suggestions and there is no common answer.我在 google 和 stackoverflow 上看到了很多与这个问题相关的帖子,但每个人都给出了自己的建议,但没有统一的答案。

1) i cannot see video in emulator 2) in different phone sometime rarly video is played and most of the time it give above message. 1) 我在模拟器中看不到视频 2) 在不同的手机中,有时会播放很少的视频,而且大多数时候它会给出上述消息。

my code我的代码

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();

any one guide me what is the solution to this problem any help would be appreciated.任何人指导我解决这个问题的方法是什么,任何帮助将不胜感激。

you can make a output stream using your file and get absolute path of stream then put path to video view您可以使用您的文件制作输出流并获取流的绝对路径,然后将路径放入视频视图

    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;
    }
}

and

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

}

use on error listner if alert this video can not be played如果警报无法播放此视频,请在错误侦听器上使用

in eclipse emulator video not displayed that link from website(internet).在 eclipse 模拟器视频中没有显示来自网站(互联网)的链接。 if you want to play a specific video.如果你想播放特定的视频。 then make raw folder and give following path然后制作原始文件夹并提供以下路径

String path1="android.resource://your package name/"+ R.raw.video name; String path1="android.resource://你的包名/"+ R.raw.video 名称;

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM