Playing Media(3gp or other video file) on the emulator

All your problems with Audio, Video and Images.

Playing Media(3gp or other video file) on the emulator

Postby GoKu » Wed Dec 05, 2007 10:19 am

Hello,

I have some problem to playing file video on the simulator. I write the code as in

:arrow: http://www.anddev.org/viewtopic.php?t=156

but insert the path of a file video and insert this code to set display:

Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1.                 SurfaceView surfaceView;
  2.  
  3.                 surfaceView = new SurfaceView(a);
  4.  
  5.                 mp.setDisplay(surfaceView.getHolder().getSurface());
  6.  
  7.                 setContentView(surfaceView);
Parsed in 0.031 seconds, using GeSHi 1.0.8.4


The problem is that the audio don't start and display becomae all black. Someone can to help me? Tanks!!!
GoKu
Freshman
Freshman
 
Posts: 7
Joined: Wed Dec 05, 2007 9:59 am

Top

Postby GoKu » Mon Dec 10, 2007 12:57 pm

Hi,

there is someone that can help me?....Thi is the code tha t I have wrote:

Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1. import android.app.Activity;
  2.  
  3. import android.media.AudioSystem;
  4.  
  5. import android.media.MediaPlayer;
  6.  
  7. import android.os.Bundle;
  8.  
  9. import android.view.SurfaceView;
  10.  
  11. import android.view.SurfaceHolder;
  12.  
  13. import android.view.View;
  14.  
  15. import android.view.View.OnClickListener;
  16.  
  17. import android.widget.Button;
  18.  
  19. import android.content.Context;
  20.  
  21. import android.util.Log;
  22.  
  23. import android.widget.TextView;
  24.  
  25. import android.view.Window;
  26.  
  27. import android.graphics.PixelFormat;
  28.  
  29.  
  30.  
  31. //import android.media.MediaPlayer.OnBufferingUpdateListener;
  32.  
  33. //import android.media.MediaPlayer.OnCompletionListener;
  34.  
  35. //import android.media.MediaPlayer.OnErrorListener;
  36.  
  37.  
  38.  
  39. public class videoMP extends Activity {
  40.  
  41.        
  42.  
  43.         private myAcListener myListener = new myAcListener(this);
  44.  
  45.         private Button b;
  46.  
  47.         private MediaPlayer mp;
  48.  
  49.         private TextView t;
  50.  
  51.        
  52.  
  53.     /** Called when the activity is first created.  */
  54.  
  55.     @Override
  56.  
  57.     public void onCreate(Bundle icicle) {
  58.  
  59.        
  60.  
  61.         super.onCreate(icicle);
  62.  
  63.         setContentView(R.layout.main);
  64.  
  65.        
  66.  
  67.         b = (Button) findViewById(R.id.myButton);
  68.  
  69.         b.setOnClickListener(myListener);
  70.  
  71.        
  72.  
  73.         t = (TextView) findViewById(R.id.myText);
  74.  
  75.        
  76.  
  77.        //mPreview = new Preview(this);        
  78.  
  79.    
  80.  
  81.     } // onCreate
  82.  
  83.    
  84.  
  85.     private class myAcListener implements OnClickListener
  86.  
  87.     {          
  88.  
  89.         private videoMP myMpActivity = null;
  90.  
  91.         private SurfaceView surfaceView;
  92.  
  93.         private Preview mPreview;
  94.  
  95.                
  96.  
  97.         private static final String TAG = "Hello";
  98.  
  99.        
  100.  
  101.         myAcListener(videoMP a) {
  102.  
  103.                 //Log.v(TAG, "onCreate: ===> ");
  104.  
  105.                 myMpActivity = a;
  106.  
  107.                 //surfaceView = new SurfaceView(a);
  108.  
  109.                 mp = new MediaPlayer();
  110.  
  111.                 //mp.setOnErrorListener(a);
  112.  
  113.                 //mPreview = new Preview(a);
  114.  
  115.         }
  116.  
  117.        
  118.  
  119.         public void onClick(View v)
  120.  
  121.         {              
  122.  
  123.                
  124.  
  125.                 //mp.setAudioStreamType(AudioSystem.STREAM_MUSIC);
  126.  
  127.             try {
  128.  
  129.                 mPreview = new Preview(myMpActivity);          
  130.  
  131.                 mp.setDataSource("sample.mp4");
  132.  
  133.                        
  134.  
  135.                 mp.prepare();
  136.  
  137.                 mp.setDisplay(mPreview.getHolder().getSurface());
  138.  
  139.                 int length = mp.getDuration();
  140.  
  141.                 if (length==1) {
  142.  
  143.                         t.setText("--"+mp.getDuration()+"--");
  144.  
  145.                 } // if
  146.  
  147.                 else {
  148.  
  149. //                      requestWindowFeature(Window.FEATURE_NO_TITLE);
  150.  
  151.                     getWindow().setFormat(PixelFormat.TRANSPARENT);
  152.  
  153.                         setContentView(mPreview);
  154.  
  155.                 }
  156.  
  157.             } // try
  158.  
  159.             catch (Exception e) {
  160.  
  161.                 e.toString();
  162.  
  163.             } // catch
  164.  
  165.             mp.start();
  166.  
  167.         } // OnClick
  168.  
  169.     };        
  170.  
  171. }
  172.  
  173.  
  174.  
  175. class Preview extends SurfaceView implements SurfaceHolder.Callback
  176.  
  177. {
  178.  
  179.     SurfaceHolder mHolder;
  180.  
  181.     private boolean mHasSurface;
  182.  
  183.     Preview(Context context) {
  184.  
  185.         super(context);
  186.  
  187.  
  188.  
  189.         mHolder = getHolder();
  190.  
  191.         mHolder.setCallback(this);
  192.  
  193.         mHasSurface = false;
  194.  
  195.        
  196.  
  197.         mHolder.setFixedSize(320, 240);
  198.  
  199.         //mHolder.setFixedSize(192, 242);
  200.  
  201.     } // Preview
  202.  
  203.  
  204.  
  205.     public boolean surfaceCreated(SurfaceHolder holder) {
  206.  
  207.         // The Surface has been created, start our main acquisition thread.
  208.  
  209.         mHasSurface = true;
  210.  
  211.         return true;
  212.  
  213.     }
  214.  
  215.  
  216.  
  217.     public void surfaceDestroyed(SurfaceHolder holder) {
  218.  
  219.         // Surface will be destroyed when we return. Stop the preview.
  220.  
  221.         mHasSurface = false;
  222.  
  223.     }
  224.  
  225.  
  226.  
  227.     public void surfaceChanged(SurfaceHolder holder, int format, int w, int h) {
  228.  
  229.         // Surface size or format has changed. This should not happen in this
  230.  
  231.         // example.
  232.  
  233.     }
  234.  
  235.  
  236.  
  237. }
Parsed in 0.045 seconds, using GeSHi 1.0.8.4


and this is the XML that I have used:

Syntax: [ Download ] [ Hide ]
Using xml Syntax Highlighting
  1. <?xml version="1.0" encoding="utf-8"?>
  2.  
  3. <LinearLayout xmlns:android="http://schemas.android.com/apk/res/
  4. android"
  5.  
  6.    android:orientation="vertical"
  7.  
  8.    android:layout_width="fill_parent"
  9.  
  10.    android:layout_height="fill_parent"
  11.  
  12.    >
  13.  
  14. <TextView id="@+id/myText"
  15.  
  16.    android:layout_width="fill_parent"
  17.  
  18.    android:layout_height="wrap_content"
  19.  
  20.    android:text="Hello World, videoMP"
  21.  
  22.    />
  23.  
  24. <Button id="@+id/myButton"
  25.  
  26.    android:layout_width="wrap_content"
  27.  
  28.    android:layout_height="wrap_content"
  29.  
  30.    android:layout_alignParentRight="true"
  31.  
  32.    android:layout_marginLeft="10px"
  33.  
  34.    android:text="Play" />
  35.  
  36. </LinearLayout>
Parsed in 0.003 seconds, using GeSHi 1.0.8.4


when I push the button the display become black. The file .mp4
size is 650 KB. I use tha command adb push to copy file to the
emulator. Can you help me!!!!!
Tanks
GoKu
Freshman
Freshman
 
Posts: 7
Joined: Wed Dec 05, 2007 9:59 am

Postby plusminus » Mon Dec 10, 2007 1:22 pm

Hello GoKu,

did you ensure, that the paht to the file is correct ?

public void setDataSource(String path)
- Sets the data source (file-path or URL) to use.
- Parameters: path The path of the file, or the URL of the stream you want to play.


As it should throw an exception on a bad path I assume your path is correct.

The second thing:
is the TextView t updated :?:

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 GoKu » Mon Dec 10, 2007 2:14 pm

Tanks plusminus,

1) I'm ensure that path is correct. I copy the file in the emulator:

adb push "[nameFile]" sample.mp4

2) the command "mp.getDuration()" return a value != 1 and the TextView is updated;
GoKu
Freshman
Freshman
 
Posts: 7
Joined: Wed Dec 05, 2007 9:59 am

Postby GoKu » Mon Dec 10, 2007 5:03 pm

There's someone that can help me? :(...
GoKu
Freshman
Freshman
 
Posts: 7
Joined: Wed Dec 05, 2007 9:59 am

Postby GoKu » Mon Dec 10, 2007 5:46 pm

plusminus can you help me?
GoKu
Freshman
Freshman
 
Posts: 7
Joined: Wed Dec 05, 2007 9:59 am

Top

Postby plusminus » Mon Dec 10, 2007 6:48 pm

Hello Goku,

I'm having some code here, basically from here which seems to be working ^^.

But I cannot find an mp4-file < 1 MB :( ( > 1 MB seems not yet to work actually :!: )

Do you have such a file :?:

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 GoKu » Tue Dec 11, 2007 9:49 am

Hello plusminus,

I have a MP4 file that is 650 KB but can't to upload it (is too great). Can to do your private email?

Tanks
GoKu
Freshman
Freshman
 
Posts: 7
Joined: Wed Dec 05, 2007 9:59 am

Postby plusminus » Tue Dec 11, 2007 2:33 pm

Hello Goku,

the Email :darrow: below each of my posts should be working :darrow: .
It is, without all the dashes:
p_l-u_s-m_i-n_u-s @ an_dd_ev.o r g


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

Hey,you have to make your player activiy transparent

Postby xxw8393 » Thu Jan 24, 2008 2:57 am

You need to add the follow code into you onCreate()

Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1. getWindow().setFormat(PixelFormat.TRANSPARENT);
Parsed in 0.032 seconds, using GeSHi 1.0.8.4


That may help.
xxw8393
Once Poster
Once Poster
 
Posts: 1
Joined: Thu Jan 24, 2008 2:53 am

Postby iurp » Tue Apr 01, 2008 10:19 am

Use the VideoView from the new SDK, very easy
iurp
Freshman
Freshman
 
Posts: 6
Joined: Tue Apr 01, 2008 8:42 am

Postby bins1984 » Tue May 27, 2008 11:18 am

hiiiiiiiiiiiiiii


but still video view is playing only the file which is stored in the emulator only,and i am not able to play a web url file...
why thats happening !!! can anybody help me to do this???

check this link...

http://www.anddev.org/not_getting_the_v ... t2183.html

with regards bins..........
User avatar
bins1984
Experienced Developer
Experienced Developer
 
Posts: 67
Joined: Fri Feb 08, 2008 8:20 am
Location: India

Top

Return to Multimedia Problems

Who is online

Users browsing this forum: No registered users and 11 guests