Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3953270
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T01:57:17+00:00 2026-05-20T01:57:17+00:00

i want to play a mp4 video. so i tried below method private void

  • 0

i want to play a mp4 video. so i tried below method

 private void playVideo() {
        try {

            final String path = s;
            Log.v(TAG, "path: " + path);
            if (path == null || path.length() == 0) {
            Toast.makeText(VideoPlay1.this, "File URL/path is empty",
                        Toast.LENGTH_LONG).show();

            } else {
                // If the path has not changed, just start the media player
                if (path.equals(current) && mVideoView != null) {
                    MediaController mediaController = new MediaController(this);
                    mediaController.setAnchorView(mVideoView);  
                  Uri video = Uri.parse(getDataSource(path));
                    Log.e("Uri video",video.toString());
                    mVideoView.setMediaController(mediaController);
                    mVideoView.setVideoURI(video);    
                     mVideoView.setVideoPath(getDataSource(path));
                    mVideoView.setOnPreparedListener(new OnPreparedListener() {

                        public void onPrepared(MediaPlayer arg0) {
                            dialog.dismiss();
                            mVideoView.start();
                        }
                    });
                    mVideoView.requestFocus();
                return;
            }
            current = path;

            MediaController mediaController = new MediaController(this);
            Uri video = Uri.parse(getDataSource(path));

            Log.e("Uri video",video.toString());
            mVideoView.setMediaController(mediaController);
            mVideoView.setVideoURI(video);    
             mVideoView.setVideoPath(getDataSource(path));
                mVideoView.setOnPreparedListener(new OnPreparedListener() {

                    public void onPrepared(MediaPlayer arg0) {
                        dialog.dismiss();
                        mVideoView.start();
                    }
                });
            mVideoView.requestFocus();
   }
        } catch (Exception e) {
            Log.e(TAG, "error123: " + e.getMessage(), e);
            if (mVideoView != null) {
                mVideoView.stopPlayback();
            }
        }
    }
    @Override
    public boolean onKeyDown(int keyCode, KeyEvent event)  {
        if (Integer.parseInt(android.os.Build.VERSION.SDK) < 5
                && keyCode == KeyEvent.KEYCODE_BACK
                && event.getRepeatCount() == 0) {
            Log.d("CDA", "onKeyDown Called");
            onBackPressed();
        }
        return super.onKeyDown(keyCode, event);
    }

    public void onBackPressed() {

        Log.d("CDA", "onBackPressed Called");
        mVideoView.stopPlayback();
        Intent setIntent = new Intent(VideoPlay1.this,VideoPage.class);
        startActivity(setIntent); 
        finish();
        return;
    }
    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();
            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;
        }
    }

the above is working it takes more time to play the video so please tell me if there is another way.

Thank you.

Best Regards.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-20T01:57:18+00:00Added an answer on May 20, 2026 at 1:57 am

    Sorry, but streaming a video to a mobile device takes time. You are limited by the connection, not the code

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want to develop a j2me application that will play a video file(.mp4) by
I have a .y4m video file, and I want to convert it to .mp4
I want to play a video, so I'm using action_view like this. intent.setAction(android.content.Intent.ACTION_VIEW); Does
I want to play the video as splash screen.I have implement the play video
I want to play my video on my web page, video is about two
i want to play a flv video from a remote server i search on
I want to play a movie in my app and the video is stored
I want to play around with silverlight without having to buy a Visual Studio
I want to play around a bit with FLASH for app development. I'm looking
I want to play a movie file or any animation file till the time

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.