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 6357285
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T23:08:09+00:00 2026-05-24T23:08:09+00:00

I save a video, test.mp4 , in my project’s res/raw directory. I have my

  • 0

I save a video, test.mp4, in my project’s res/raw directory. I have my SurfaceView declared as such:

  <SurfaceView android:id="@+id/surface"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_gravity="center">
  </SurfaceView>

Then, in my activity’s onCreate () method, I have the following:

private MediaPlayer mp;
private SurfaceView view;
private SurfaceHolder holder;

/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState)
{
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);
    view = (SurfaceView) findViewById (R.id.surface);
    holder = view.getHolder();
    holder.setKeepScreenOn (true); 
    mp = MediaPlayer.create(this.getBaseContext (), R.raw.test);
    mp.setDisplay (holder);
    mp.setLooping (true);
    mp.start();
}

I don’t get why it doesn’t show the video, even if I set the display. I’m running on API 7 (2.1.1) and I get the audio. I need a Video-only type of interface, without the control panel. As far as I know, VideoView, although simpler than MediaPlayer, has a built-in control layer. Also, I don’t see a way to use VideoView on a resource. If there are workarounds for these two issues I have, or if my assumption of VideoView is wrong, I’d appreciate being told.


UPDATE: I am currently using the VideoView class. My assumption really was wrong about automatically having a UI control panel. Still, I have NOT been able to play videos stored in res/raw via the MediaPlayer class; it always fails when I call prepare () or the audio plays, but the video doesn’t. Because of this, my question still stands.

If anyone runs into my question about how I used VideoView, let me save you some trouble in looking for how to retrieve a video in res/raw. The following snippet assumes you have a VideoView with an id of view in a layout file, main.xml:

public class generalActivity extends Activity {
    @Override
    public void onCreate (Bundle icicle) {
        super.onCreate (icicle);
        this.setContent (R.layout.main);

        // You know the that view is an instance of VideoView, so cast it as such
        VideoView v = (VideoView) this.findViewById (R.id.view);

        // This is the name of the video WITHOUT the file extension.
        // In this example, the name of the video is 'test.mp4'
        String videoName = "test"

        // You build the URI to your video here
        StringBuilder uriPathBuilder = new StringBuilder ();
        uriPathBuilder.append ("android.resource://");
        uriPathBuilder.append (this.getPackageName ());
        uriPathBuilder.append (File.separator);
        uriPathBuilder.append ("raw");
        uriPathBuilder.append (File.separator);
        uriPathBuilder.append (videoName);
        Uri uri = Uri.parse (uriPathBuilder.toString ());

        view.setVideoURI (uri);
        view.start ();
    }
}

Here’s the link that I used as a reference to get the uri path: reference link

I’m leaving this open because I asked if I could play video in res/raw using MediaPlayer, and not VideoView. Even if I got it to work the way I wanted using VideoView, as far as I know, there are still things MediaPlayer can do that VideoView can’t. I could be wrong though, so if you just need to show a video and don’t need anything advanced, I’m pretty sure VideoView will suffice.

Oh, and thanks to @Ravi for all the help.

  • 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-24T23:08:09+00:00Added an answer on May 24, 2026 at 11:08 pm

    I think a better approach would be to use VideoView instead of MediaPlayer, as it wraps the player, the surface and the holder for you, if you fail to see the video in VideoView, then maybe the video file cannot be played on android.

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

Sidebar

Related Questions

Basiclly, I want to capture audio/video. Run it through a mp4 muxer and save
First question is, given a url to an mp4 video, how can I save
In my project I am trying to save video to the iPhone after being
I made an app with a feature to capture and save video. I have
Is there any way for me to save a video in the Documents directory
@Service @Repository @Transactional public class VideoService { @PersistenceContext EntityManager entityManager; public void save(Video video)
Can you save recorded video to isolated storage on Windows Phone 7? And if
I'm trying to find a way to save a video file. Initially I'd put
I want to extract first frame of uploaded video and save it as image
is there anyway to save the following flash video locally, perhaps by streaming it

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.