Play Video From Raw Folder

All your problems with Audio, Video and Images.

Play Video From Raw Folder

Postby Sterallures » Thu Dec 23, 2010 10:13 pm

Heya,

I've just started to work on a program to get into the game of android programming so I'm still kind of a novice but im trying to understand it all.

So here's my problem, I'm trying to play a video, the thing is, I got it working when i use a Stream from an URL with VideoView.

What I want to do now it play a video I've got in my res/raw folder but it only plays audio and I don't understand why, it doesn't give any error in my logcat as far as I can see, also couldn't really find a solution with google since most of the answers are about VideoView and just put the video on your SDCard.

I hope someone can help me find a solution.

Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1. package nl.melvin.videodemo;
  2.  
  3. import java.net.URI;
  4. import android.app.Activity;
  5. import android.net.Uri;
  6. import android.os.Bundle;
  7. import android.widget.MediaController;
  8. import android.widget.VideoView;
  9. import android.media.MediaPlayer;
  10. import android.app.AlertDialog;
  11.  
  12.  
  13. public class videodemo extends Activity {
  14.  
  15. /** Called when the activity is first created. */
  16. @Override
  17. public void onCreate(Bundle savedInstanceState) {
  18. super.onCreate(savedInstanceState);
  19. setContentView(R.layout.main);
  20.  
  21.                 try {
  22.                         MediaPlayer mp = null;
  23.  
  24.                         if (mp == null) {
  25.                                 Uri uri = Uri.parse("android.resource://nl.melvin.videodemo/"
  26.                                                 + R.raw.mac);
  27.                                 MessageBox(uri.toString());
  28.  
  29.                                 mp = MediaPlayer.create(this, uri);
  30.                         }
  31.  
  32.                         if (mp != null) {
  33.                                 mp.start();
  34.                         } else {
  35.                                 MessageBox("No MP");
  36.                         }
  37.                 } catch (Exception x) {
  38.                         MessageBox(x.toString());
  39.                 }
  40.         }
  41.  
  42.         void MessageBox(String msg) {
  43.                 new AlertDialog.Builder(this).setMessage(msg)
  44.                                 .setPositiveButton("OK", null).show();
  45.  
  46.         }
  47.  
  48. }
Parsed in 0.044 seconds, using GeSHi 1.0.8.4
Last edited by Sterallures on Mon Dec 27, 2010 1:05 pm, edited 1 time in total.
Sterallures
Freshman
Freshman
 
Posts: 6
Joined: Thu May 20, 2010 9:37 pm

Top

Re: MediaPlayer Uri.Parse

Postby Ready wu » Fri Dec 24, 2010 4:09 am

hi Sterallures
I think you should call the method:
setDisplay (SurfaceHolder sh)
Sets the SurfaceHolder to use for displaying the video portion of the media. This call is optional. Not calling it when playing back a video will result in only the audio track being played.
Ready wu
Freshman
Freshman
 
Posts: 3
Joined: Wed Sep 02, 2009 3:52 am
Location: Shanghai,China

Re: MediaPlayer Uri.Parse

Postby Sterallures » Fri Dec 24, 2010 8:57 am

Oke Thanks, I'm going to try that and hope that will then playback the video part.

Will get back to you!
Sterallures
Freshman
Freshman
 
Posts: 6
Joined: Thu May 20, 2010 9:37 pm

Re: MediaPlayer Uri.Parse

Postby Sterallures » Mon Dec 27, 2010 1:03 pm

I've been busy with setDisplay but I wasn't totally sure how to use it so I did the following:
Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1. package nl.melvin.videodemo;
  2.  
  3. import android.app.Activity;
  4. import android.os.Bundle;
  5. import android.media.MediaPlayer;
  6. import android.view.SurfaceHolder;
  7. import android.view.SurfaceView;
  8.  
  9.  
  10. public class videodemo extends Activity {
  11.  
  12.         public SurfaceHolder holder;
  13.         public SurfaceView surfaceView;
  14.        
  15.  
  16.         /** Called when the activity is first created. */
  17.         @Override
  18.         public void onCreate(Bundle savedInstanceState) {
  19.         super.onCreate(savedInstanceState);
  20.         setContentView(R.layout.main);
  21.          
  22.        
  23.                 MediaPlayer mp = MediaPlayer.create(this, R.raw.mac);
  24.        
  25.                 mp.setDisplay(holder);
  26.                 mp.start();
  27.                
  28.           }
  29.          
  30. }
  31.  
Parsed in 0.033 seconds, using GeSHi 1.0.8.4


It still only plays the audio, got another idea?
Sterallures
Freshman
Freshman
 
Posts: 6
Joined: Thu May 20, 2010 9:37 pm

Top

Return to Multimedia Problems

Who is online

Users browsing this forum: Exabot [Bot], Google [Bot] and 10 guests