3

freinds,

i am using following code to display a mp4 video in my application and facing following problems

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.

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.

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.

6
  • i think there is some thing wrong with codec for .mp4 videos have you tried the videos with different fps and quality, is this makes any difference?
    – Badr
    Jun 20, 2011 at 11:08
  • may b could you please explain bit more yes it could be the problem. Jun 20, 2011 at 12:23
  • what does it mean? different fps and quality Jun 20, 2011 at 12:24
  • thanks for your url,it helped me to test my app. Nov 2, 2011 at 7:22
  • Mr. @While-E your moral duty is to do help of needy person, not to do waist argument to them. Any person who really needs help post his/her question here, it is not necessary that he/she must be perfect in everything. So take care dear... Mar 19, 2012 at 6:35

2 Answers 2

0

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

0

in eclipse emulator video not displayed that link from website(internet). 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;

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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.