Playing Video Problem

All your problems with Audio, Video and Images.

Playing Video Problem

Postby iratao » Tue Sep 01, 2009 9:09 am

Hi there!
I am trying to run the source code"Simple Video" of Unlocking Android in chapter 10. But when i launch this program , it tells me cannot play the video.
Here is the code
Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1. public class SimpleVideo extends Activity {
  2.         private VideoView myVideo;
  3.         private MediaController mc;
  4.         @Override
  5.         public void onCreate(Bundle icicle) {
  6.                 super.onCreate(icicle);
  7.                 getWindow().setFormat(PixelFormat.TRANSLUCENT);
  8.                 setContentView(R.layout.main);
  9.                 Button bPlayVideo=(Button)findViewById(R.id.playvideo);
  10.                 bPlayVideo.setOnClickListener(new View.OnClickListener() {
  11.                 public void onClick(View view) {
  12.                         mc.show();      }
  13.                                 });
  14.                         myVideo=(VideoView)findViewById(R.id.video);
  15.                         myVideo.setVideoPath("/tmp/test.mp4");
  16.                         mc=new MediaController(this);
  17.                         mc.setMediaPlayer(myVideo);
  18.                         myVideo.setMediaController(mc);
  19.                         myVideo.requestFocus();
  20.                 }
  21. }
Parsed in 0.033 seconds, using GeSHi 1.0.8.4


Here is the log info:
09-01 07:46:43.306: WARN/InputManagerService(578): Window already focused, ignoring focus gain of: com.android.internal.view.IInputMethodClient$Stub$Proxy@4371f690
09-01 07:47:01.846: WARN/KeyCharacterMap(715): No keyboard for id 0
09-01 07:47:01.858: WARN/KeyCharacterMap(715): Using default keymap: /system/usr/keychars/qwerty.kcm.bin
09-01 07:47:02.068: VERBOSE/VideoView(725): reset duration to -1 in openVideo
09-01 07:47:02.116: ERROR/PlayerDriver(554): Command PLAYER_SET_DATA_SOURCE completed with an error or info PVMFErrNotSupported
09-01 07:47:02.116: ERROR/MediaPlayer(725): error (1, -4)
09-01 07:47:02.287: ERROR/MediaPlayer(725): Error (1,-4)
09-01 07:47:02.287: DEBUG/VideoView(725): Error: 1,-4
09-01 07:47:02.426: WARN/InputManagerService(578): Starting input on non-focused client com.android.internal.view.IInputMethodClient$Stub$Proxy@4361f8d0 (uid=10022 pid=715)
09-01 07:47:04.397: WARN/InputManagerService(578): Window already focused, ignoring focus gain of: com.android.internal.view.IInputMethodClient$Stub$Proxy@437288b8
09-01 07:47:05.367: WARN/KeyCharacterMap(725): No keyboard for id 0
09-01 07:47:05.377: WARN/KeyCharacterMap(725): Using default keymap: /system/usr/keychars/qwerty.kcm.bin
09-01 07:47:05.786: WARN/InputManagerService(578): Starting input on non-focused client com.android.internal.view.IInputMethodClient$Stub$Proxy@436cd8f8 (uid=10021 pid=725)
09-01 07:47:05.956: WARN/KeyCharacterMap(618): No keyboard for id 0
09-01 07:47:05.966: WARN/KeyCharacterMap(618): Using default keymap: /system/usr/keychars/qwerty.kcm.bin
09-01 07:47:11.318: DEBUG/dalvikvm(715): GC freed 659 objects / 61240 bytes in 306ms
09-01 07:47:11.856: DEBUG/AndroidRuntime(745): >>>>>>>>>>>>>> AndroidRuntime START <<<<<<<<<<<<<<
09-01 07:47:11.866: DEBUG/AndroidRuntime(745): CheckJNI is ON
09-01 07:47:12.206: INFO/jdwp(745): received file descriptor 20 from ADB
09-01 07:47:12.226: DEBUG/AndroidRuntime(745): --- registering native functions ---
09-01 07:47:13.286: INFO/ActivityManager(578): Starting activity: Intent { flags=0x10000000 comp={com.msi.manning.chapter10.SimpleVideo/com.msi.manning.chapter10.SimpleVideo.SimpleVideo} }
09-01 07:47:13.376: DEBUG/AndroidRuntime(745): Shutting down VM
09-01 07:47:13.388: DEBUG/dalvikvm(745): DestroyJavaVM waiting for non-daemon threads to exit
09-01 07:47:13.457: DEBUG/dalvikvm(745): DestroyJavaVM shutting VM down
09-01 07:47:13.457: DEBUG/dalvikvm(745): HeapWorker thread shutting down
09-01 07:47:13.467: DEBUG/dalvikvm(745): HeapWorker thread has shut down
09-01 07:47:13.486: DEBUG/jdwp(745): JDWP shutting down net...
09-01 07:47:13.486: DEBUG/jdwp(745): +++ peer disconnected
09-01 07:47:13.486: INFO/dalvikvm(745): Debugger has detached; object registry had 2 entries
09-01 07:47:13.517: DEBUG/dalvikvm(745): VM cleaning up
09-01 07:47:13.746: DEBUG/dalvikvm(745): LinearAlloc 0x0 used 639228 of 4194304 (15%)
09-01 07:47:13.997: WARN/IInputConnectionWrapper(618): showStatusIcon on inactive InputConnection
09-01 07:47:14.106: VERBOSE/VideoView(715): reset duration to -1 in openVideo
09-01 07:47:14.216: ERROR/PlayerDriver(554): Command PLAYER_SET_DATA_SOURCE completed with an error or info PVMFErrNotSupported
09-01 07:47:14.216: ERROR/MediaPlayer(715): error (1, -4)
09-01 07:47:14.286: INFO/ActivityManager(578): Displayed activity com.msi.manning.chapter10.SimpleVideo/.SimpleVideo: 1002 ms
09-01 07:47:14.317: ERROR/MediaPlayer(715): Error (1,-4)
09-01 07:47:14.347: DEBUG/VideoView(715): Error: 1,-4
09-01 07:47:20.086: DEBUG/dalvikvm(725): GC freed 637 objects / 58080 bytes in 174ms
09-01 07:47:25.167: DEBUG/dalvikvm(618): GC freed 438 objects / 18680 bytes in 234ms
09-01 07:52:01.647: DEBUG/dalvikvm(578): GC freed 12098 objects / 632840 bytes in 1522ms

Thank you first! It's my first question here and english is not my mother tongue. I hope my statement is clear.
iratao
Freshman
Freshman
 
Posts: 7
Joined: Tue Sep 01, 2009 8:49 am

Top

Postby iratao » Thu Sep 03, 2009 3:25 am

Here is the answer:
I just forgot to push the raw .mp4 file to the sdcard.
iratao
Freshman
Freshman
 
Posts: 7
Joined: Tue Sep 01, 2009 8:49 am

Postby John » Fri Oct 16, 2009 11:29 am

iratao wrote:Here is the answer:
I just forgot to push the raw .mp4 file to the sdcard.


Hi iratao,

Your code helped me a lot to play a sample video from SDCard using your code snippet. But i want to run a Video file from raw folder which is available on my project resource. How to do that with your code? I tried to give my raw project folder path as
...................................
...................................
private String filename = "/raw/sample.mp4"
...................................
...................................
myVideo.setVideoPath(filename);
...................................

But it says "Cannot play video". I'm sure that i'm giving path as wrong. Could you please advise me how to resolve it?

thanks a lot for your code.
John
Freshman
Freshman
 
Posts: 7
Joined: Fri Oct 16, 2009 8:36 am

Postby Joriz » Fri Oct 16, 2009 5:22 pm

You can use:

MediaPlayer mp = MediaPlayer.create(this, R.raw.sample)
Joriz
Freshman
Freshman
 
Posts: 3
Joined: Sat Oct 10, 2009 10:50 pm
Location: Amsterdam

Postby John » Fri Oct 16, 2009 5:53 pm

Joriz wrote:You can use:

MediaPlayer mp = MediaPlayer.create(this, R.raw.sample)


Hi,

I tried to play a video from a raw folder available in my project resource by using the following simple code snippet provided by Android developers website.

public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);

MediaPlayer mp = MediaPlayer.create(getBaseContext(), R.raw.sample); // sample: it is a .m4v file.
mp.start();

}

But when i run my code, it plays only the sound, i didn't see video player or video. Only sound is coming. I even added prepare() , but still the same problem May i know what should be the problem and how to resolve this issue?

Note: I'm trying on Android OS 1.5 HTC T-mobile handset.
John
Freshman
Freshman
 
Posts: 7
Joined: Fri Oct 16, 2009 8:36 am

Postby Joriz » Fri Oct 16, 2009 10:33 pm

But when i run my code, it plays only the sound, i didn't see video player or video. Only sound is coming.


This is standard behaviour for the mediaplayer. If you want to see the video as well, you'll have to set a Surface for the mediaplayer to show the video. First, create a SurfaceView in your layout, then use the following code:

Code: Select all
SurFaceView v = (SurfaceView) findViewById(R.id.mysurfaceview);
SurfaceHolder h = v.getHolder();
MediaPlayer mp = MediaPlayer.create(this, R.raw.sample);
mp.setDisplay(h);


I'm trying a similar thing at the moment, but the emulator won't show my video and just gives some weird error-like messages. I think this might be an emulator/computer problem, so I ordered an HTC Hero to test my code. If the code above works for you in an emulator, please let me know!
Joriz
Freshman
Freshman
 
Posts: 3
Joined: Sat Oct 10, 2009 10:50 pm
Location: Amsterdam

Top

Postby jack » Fri Oct 16, 2009 11:26 pm

Oh yeah, thank you JORIZ.
I'll try SurfaceView now and get back to you with the result.
jack
Freshman
Freshman
 
Posts: 5
Joined: Fri Oct 16, 2009 9:09 pm

Postby jack » Fri Oct 16, 2009 11:32 pm

I created a SurfaceView in main.xml. It is showing a small rectanlgle, is this correct or i need to make to full screen, if Yes how to do that?
And when i added your code, it throws error as "SurFaceView cannot be resolve to a type". I imported SurfaceView as well. Do i need to do anything extra?
jack
Freshman
Freshman
 
Posts: 5
Joined: Fri Oct 16, 2009 9:09 pm

Postby jack » Fri Oct 16, 2009 11:44 pm

I am able to run your Surface code now on the device. I kept playing video at startup of my application. It throws error as 'The application has stopped unexpectedly. please try again'.
What is the problem?
jack
Freshman
Freshman
 
Posts: 5
Joined: Fri Oct 16, 2009 9:09 pm

Postby Joriz » Sun Oct 18, 2009 11:05 pm

I don't know... Have a look at the LogCat. You can put additional debug messages there using Log.d(TAG, MESSAGE).
Joriz
Freshman
Freshman
 
Posts: 3
Joined: Sat Oct 10, 2009 10:50 pm
Location: Amsterdam

Postby Beros_ » Fri Jan 29, 2010 4:34 pm

Hi everyone!

I was very supprised when I found out that it's impossible to set speed of video playback on Android.

For example that video plays with 200% of speed, or 50% or -25%...

Does anybody know how to set video playback speed?

There is function to set position in video, in miliseconds, but it continues to play after that and I just want that video is still on requested position. Whenever i call video.pause() function it blocks whole video. So there is definitely some bug in pause() function.
Beros_
Freshman
Freshman
 
Posts: 7
Joined: Fri Jan 29, 2010 4:29 pm
Location: Croatia

Top

Return to Multimedia Problems

Who is online

Users browsing this forum: Majestic-12 [Bot] and 14 guests