簡體   English   中英

抱歉,此視頻無法在 videoview 中播放?

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

朋友們,

我正在使用以下代碼在我的應用程序中顯示 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();

任何人指導我解決這個問題的方法是什么,任何幫助將不勝感激。

您可以使用您的文件制作輸出流並獲取流的絕對路徑,然后將路徑放入視頻視圖

    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

}

如果警報無法播放此視頻,請在錯誤偵聽器上使用

在 eclipse 模擬器視頻中沒有顯示來自網站(互聯網)的鏈接。 如果你想播放特定的視頻。 然后制作原始文件夾並提供以下路徑

String path1="android.resource://你的包名/"+ R.raw.video 名稱;

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

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM