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

  • SEARCH
  • Home
  • 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 6854331
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T01:37:13+00:00 2026-05-27T01:37:13+00:00

I’m using the following code to play a .mp4 video on my android device.

  • 0

I’m using the following code to play a .mp4 video on my android device. I have 3 problems,

  1. using this code when I press the back button on the device the sound would still continoue to play

  2. It doesn’t play the video, only plays the sound!

  3. I don’t know how to get controller for the video so the user can stop the video, go back or forth on the video.

    VideoView videoHolder = new VideoView(this);
    videoHolder.setMediaController(new MediaController(this));
    getWindow().setFormat(PixelFormat.TRANSLUCENT);    
    MediaPlayer mediaPlayer = new MediaPlayer();
    Uri myUri = Uri.parse("android.resource://" + getPackageName() + "/" + R.drawable.video);
    
    videoHolder.setVideoURI(myUri);
    mediaPlayer.setAudioStreamType(AudioManager.STREAM_MUSIC);
    mediaPlayer.setDataSource(getApplicationContext(), myUri);
    mediaPlayer.prepare();      
    mediaPlayer.start();
    
    videoHolder.requestFocus();
    videoHolder.start();
    
  • 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-27T01:37:14+00:00Added an answer on May 27, 2026 at 1:37 am

    1) Override onBackPressed in your activity:

    @Override
    public void onBackPressed() {
        mediaPlayer.stopPlayback();
        super.onBackPressed();        
    }
    

    2) Is it a valid video format? Are you using emulator or a real device? If you use an emulator, try a real device instead. I recall similar issues before.
    But I also notice: did you put your video in the drawable folder?

    R.drawable.video
    

    I don’t think that will work, you cannot play videos from there. Use the resources/raw folder instead. btw: Audio can be played from assets folder directly, while video cannot; video can only played from the raw folder or if you copy it to the apps files folder (getFilesDir()) – or sdcard of course.

    3) Why are you using a VideoView AND a MediaPlayer, instead of just a VideoView? You should get rid of the mediaPlayer and just use the VideoView. This line

    videoHolder.setMediaController(new MediaController(this));
    

    looks correct and sets the media controller, with which the user can seek in the video.
    Programatically you can also use seekTo() to go back and forth in a video.

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

Sidebar

Related Questions

I have this code: - (void)parser:(NSXMLParser *)parser foundCDATA:(NSData *)CDATABlock { NSString *someString = [[NSString
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
this is what i have right now Drawing an RSS feed into the php,
I'm using v2.0 of ClassTextile.php, with the following call: $testimonial_text = $textile->TextileRestricted($_POST['testimonial']); ... and
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
I have thousands of HTML files to process using Groovy/Java and I need to
I ran into a problem. Wrote the following code snippet: teksti = teksti.Trim() teksti
I have some data like this: 1 2 3 4 5 9 2 6
I'm new to using the Perl treebuilder module for HTML parsing and can't figure
That's pretty much it. I'm using Nokogiri to scrape a web page what has

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.