Audio, but no Video during Media Player playback

All your problems with Audio, Video and Images.

Audio, but no Video during Media Player playback

Postby bugzilla » Tue Oct 07, 2008 2:43 pm

I have been trying to play a video which is included as a resource in my program. I can hear the audio but can't see the video. I've heard that you should use "prepare" when using the MediaPlayer class, but does anyone have any code to show how this works?

Here is the code for my program so far

Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1. package clt.videoplayer;
  2.  
  3.  
  4.  
  5. import android.net.Uri;
  6.  
  7. import android.os.Bundle;
  8.  
  9. import android.widget.VideoView;
  10.  
  11. import android.media.MediaPlayer;  
  12.  
  13. import android.app.Activity;  
  14.  
  15. import java.io.IOException;
  16.  
  17.  
  18.  
  19. public class VideoPlayer extends Activity {
  20.  
  21.     @Override
  22.  
  23.     public void onCreate(Bundle icicle) {
  24.  
  25.         super.onCreate(icicle);
  26.  
  27.         setContentView(R.layout.main);
  28.  
  29.        
  30.  
  31.         MediaPlayer mp=MediaPlayer.create(getBaseContext(),R.raw.test);
  32.  
  33.         mp.start();
  34.  
  35.  
  36.  
  37.     }
  38.  
  39. }
Parsed in 0.032 seconds, using GeSHi 1.0.8.4


"Main.xml"
Syntax: [ Download ] [ Hide ]
Using xml Syntax Highlighting
  1. <?xml version="1.0" encoding="utf-8"?>
  2.  
  3.  <LinearLayout android:id="@+id/LinearLayout01" android:layout_width="wrap_content" android:layout_height="wrap_content" xmlns:android="http://schemas.android.com/apk/res/android"><VideoView android:layout_height="wrap_content" android:id="@+id/media_video" android:layout_width="fill_parent"></VideoView>
  4.  
  5. <EditText android:id="@+id/EditText01" android:layout_height="wrap_content" android:layout_width="fill_parent"></EditText>
  6.  
  7. </LinearLayout>
Parsed in 0.002 seconds, using GeSHi 1.0.8.4
bugzilla
Freshman
Freshman
 
Posts: 3
Joined: Tue Oct 07, 2008 2:28 pm

Top

Formats used

Postby bugzilla » Tue Oct 07, 2008 2:55 pm

I forgot to say. I have tried this using an .m4v file and a .3gp file. I created each using Quicktime Pro using iPhone preset settings. There are no Android specific settings I can find so far.
bugzilla
Freshman
Freshman
 
Posts: 3
Joined: Tue Oct 07, 2008 2:28 pm

Postby plusminus » Tue Oct 07, 2008 7:27 pm

Did you try a mp4 file :?: in m5 (odl sdk) those worked when they were smaller than 1 mb.

Anyway I'm not the media-guy (never dealt with it more than simply playing a audio-file).

But maybe someone out there knows :?:

Best Regards,
plusminus
Image
Image | Android Development Community / Tutorials
User avatar
plusminus
Site Admin
Site Admin
 
Posts: 2688
Joined: Wed Nov 14, 2007 8:37 pm
Location: Schriesheim, Germany

Postby bugzilla » Tue Oct 07, 2008 8:00 pm

plusminus wrote:Did you try a mp4 file :?: in m5 (odl sdk) those worked when they were smaller than 1 mb.

Anyway I'm not the media-guy (never dealt with it more than simply playing a audio-file).

But maybe someone out there knows :?:

Best Regards,
plusminus


Yes. I tried and mp4 file that is less than 1MB but that has the same problem. Is this a bug in the simulator? I hope the actual phone plays video files greater than 1MB or else it will be useless as a multimedia device.
bugzilla
Freshman
Freshman
 
Posts: 3
Joined: Tue Oct 07, 2008 2:28 pm

Postby plusminus » Tue Oct 07, 2008 8:18 pm

Yeah, somehow it works ;) I've seen a couple of apps that play video.

Regards,
plusminus
Image
Image | Android Development Community / Tutorials
User avatar
plusminus
Site Admin
Site Admin
 
Posts: 2688
Joined: Wed Nov 14, 2007 8:37 pm
Location: Schriesheim, Germany

Postby tabrej.khan » Sat Dec 06, 2008 2:21 pm

I am too having the same issue in SDK 1.0
It is able to play the MP4 more than 1MB but I am not able to see the video... here is the code snippet...
private void playLocalVideo() {
try {
mp = MediaPlayer.create(getBaseContext(), R.raw.bottleopener); //R.raw.vedio);
mp.start();
} catch (Exception e) {
Log.e("Error Param1", "Error Param 2", e);
}
}

I think I have to use VideoView or SurfaceView but don't know how to use it any idea which one and how to use it???
Even though I am looking the samples given in the SDK and try my own. :)
User avatar
tabrej.khan
Freshman
Freshman
 
Posts: 8
Joined: Wed Jul 16, 2008 6:16 am
Location: Bangalore, Karnataka

Top

Postby amulya » Tue Feb 23, 2010 3:25 am

i tried using surfaceview but still cant see video. Here is my code

package com.android.mediaplayerpoc;

import android.R.*;
import android.app.Activity;
import android.os.Bundle;
import android.view.SurfaceHolder;
import android.view.SurfaceView;
import android.media.MediaPlayer;

public class videoplayer extends Activity {
/** Called when the activity is first created. */
MediaPlayer mp;
private SurfaceView preview;
private SurfaceHolder holder;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
preview = (SurfaceView) findViewById(R.id.preview);
holder = preview.getHolder();
mp=new MediaPlayer();
mp.setScreenOnWhilePlaying(true);
mp=MediaPlayer.create(getBaseContext(),R.raw.documentariesandyou);
mp.setDisplay(holder);
mp.start();
}
}

The file format is 3gp.
If anybody could tell me if I am missing something, i'd appreciate it very much

thanks in advance
amulya
tabrej.khan wrote:I am too having the same issue in SDK 1.0
It is able to play the MP4 more than 1MB but I am not able to see the video... here is the code snippet...
private void playLocalVideo() {
try {
mp = MediaPlayer.create(getBaseContext(), R.raw.bottleopener); //R.raw.vedio);
mp.start();
} catch (Exception e) {
Log.e("Error Param1", "Error Param 2", e);
}
}

I think I have to use VideoView or SurfaceView but don't know how to use it any idea which one and how to use it???
Even though I am looking the samples given in the SDK and try my own. :)
Learning to learn.
amulya
Freshman
Freshman
 
Posts: 2
Joined: Tue Feb 23, 2010 3:16 am

Postby mrco » Tue Feb 23, 2010 2:02 pm

Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1. mp=new MediaPlayer();
  2.  
  3. mp.setScreenOnWhilePlaying(true);
  4.  
  5. mp=MediaPlayer.create(getBaseContext(),R.raw.documentariesandyou);
  6.  
  7. mp.setDisplay(holder);
Parsed in 0.033 seconds, using GeSHi 1.0.8.4

That's wrong. In first line you create new MediaPlayer, and then in line 3 you create media player again.
Here sample from my working app:
Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1.  
  2.                         mp = new MediaPlayer();
  3.  
  4.                         SurfaceHolder videoHolder = splashScreenVideoUI.getHolder();
  5.  
  6.                         mp.setScreenOnWhilePlaying(true);
  7.  
  8.                         mp.setDisplay(videoHolder);
  9.  
  10.                         mp.setAudioStreamType(AudioManager.STREAM_MUSIC);
  11.  
  12.  
  13.  
  14.                         mp.setOnPreparedListener(this);
  15.  
  16.                         mp.setOnCompletionListener(this);
  17.  
  18.  
  19.  
  20.                         AssetFileDescriptor afd = context.getResources().openRawResourceFd(R.raw.talent_mania);
  21.  
  22.                         mp.setDataSource(afd.getFileDescriptor(),
  23.  
  24.                                         afd.getStartOffset(), afd.getLength());
  25.  
  26.                         mp.prepareAsync();
  27.  
  28.  
Parsed in 0.036 seconds, using GeSHi 1.0.8.4
mrco
Experienced Developer
Experienced Developer
 
Posts: 71
Joined: Fri Jan 15, 2010 11:31 am
Location: 2V Software

Top

Return to Multimedia Problems

Who is online

Users browsing this forum: No registered users and 19 guests