Not Getting the Video of VideoFile

All your problems with Audio, Video and Images.

Not Getting the Video of VideoFile

Postby bins1984 » Mon May 26, 2008 11:35 am

hi...

i am trying play a 3gp file ,which is having the video content but is getting work but not getting the video of that file,only able to hear the song,i tried with video view and tried with the surface also but still unable to execute ,can anybody help me???????????

Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1. package com.google.android.Videoplayer;
  2.  
  3.  
  4.  
  5. import android.app.Activity;
  6.  
  7. import android.graphics.PixelFormat;
  8.  
  9. import android.media.MediaPlayer;
  10.  
  11. import android.media.MediaPlayer.OnBufferingUpdateListener;
  12.  
  13. import android.media.MediaPlayer.OnCompletionListener;
  14.  
  15. import android.media.MediaPlayer.OnErrorListener;
  16.  
  17. import android.os.Bundle;
  18.  
  19. import android.util.Log;
  20.  
  21. import android.view.Surface;
  22.  
  23. import android.view.SurfaceHolder;
  24.  
  25. import android.view.SurfaceView;
  26.  
  27. import android.view.View;
  28.  
  29. import android.webkit.URLUtil;
  30.  
  31. import android.widget.EditText;
  32.  
  33. import android.widget.ImageButton;
  34.  
  35. import android.widget.VideoView;
  36.  
  37.  
  38.  
  39. import java.io.File;
  40.  
  41. import java.io.FileOutputStream;
  42.  
  43. import java.io.IOException;
  44.  
  45. import java.io.InputStream;
  46.  
  47. import java.net.URL;
  48.  
  49. import java.net.URLConnection;
  50.  
  51.  
  52.  
  53. public class Videoplayer extends Activity implements  SurfaceHolder.Callback {
  54.  
  55.     private static final String TAG = "VideoPlayer";
  56.  
  57.  
  58.  
  59.     private MediaPlayer mp;
  60.  
  61.     private SurfaceView mPreview;
  62.  
  63.      private SurfaceHolder holder;
  64.  
  65.     private ImageButton mPlay;
  66.  
  67.     private ImageButton mPause;
  68.  
  69.     private ImageButton mReset;
  70.  
  71.     private ImageButton mStop;
  72.  
  73.    
  74.  
  75.  
  76.  
  77.     /**
  78.  
  79.      * Called when the activity is first created.
  80.  
  81.      */
  82.  
  83.     public void onCreate(Bundle icicle) {
  84.  
  85.         super.onCreate(icicle);
  86.  
  87.  
  88.  
  89.         setContentView(R.layout.main);
  90.  
  91.  
  92.  
  93.         // Set up the play/pause/reset/stop buttons
  94.  
  95.         mPreview = (SurfaceView) findViewById(R.id.surface);
  96.  
  97.         mPlay = (ImageButton) findViewById(R.id.play);
  98.  
  99.         mPause = (ImageButton) findViewById(R.id.pause);
  100.  
  101.         mReset = (ImageButton) findViewById(R.id.reset);
  102.  
  103.         mStop = (ImageButton) findViewById(R.id.stop);
  104.  
  105.        
  106.  
  107.         mPlay.setOnClickListener(new View.OnClickListener() {
  108.  
  109.             public void onClick(View view) {
  110.  
  111.                playVideo();
  112.  
  113.                
  114.  
  115.             }
  116.  
  117.         });
  118.  
  119.         mPause.setOnClickListener(new View.OnClickListener() {
  120.  
  121.             public void onClick(View view) {
  122.  
  123.                 if (mp != null) {
  124.  
  125.                     mp.pause();
  126.  
  127.                 }
  128.  
  129.             }
  130.  
  131.         });
  132.  
  133.         mReset.setOnClickListener(new View.OnClickListener() {
  134.  
  135.             public void onClick(View view) {
  136.  
  137.                 if (mp != null) {
  138.  
  139.                     mp.seekTo(0);
  140.  
  141.                 }
  142.  
  143.             }
  144.  
  145.         });
  146.  
  147.         mStop.setOnClickListener(new View.OnClickListener() {
  148.  
  149.             public void onClick(View view) {
  150.  
  151.                 if (mp != null) {
  152.  
  153.                     mp.stop();
  154.  
  155.                     mp.release();
  156.  
  157.                 }
  158.  
  159.             }
  160.  
  161.         });
  162.  
  163.  
  164.  
  165.         // Set the transparency
  166.  
  167.         getWindow().setFormat(PixelFormat.TRANSPARENT);
  168.  
  169.  
  170.  
  171.         // Set a size for the video screen
  172.  
  173.         holder = mPreview.getHolder();
  174.  
  175.         holder.addCallback(this);
  176.  
  177.         holder.setFixedSize(320,400);
  178.  
  179.     }
  180.  
  181.  
  182.  
  183.     private void playVideo() {
  184.  
  185.      
  186.  
  187.                
  188.  
  189.                  mp=MediaPlayer.create(Videoplayer.this, R.raw.crazy);
  190.  
  191.                  mp.setAudioStreamType(3);
  192.  
  193.                  mp.setDisplay(mPreview.getHolder().getSurface());
  194.  
  195.                  mp.start();
  196.  
  197.                  
  198.  
  199.        
  200.  
  201.     }
  202.  
  203.    
  204.  
  205.     public void surfaceCreated(SurfaceHolder surfaceholder) {
  206.  
  207.         Log.d(TAG, "surfaceCreated called");
  208.  
  209.         //return true;
  210.  
  211.     }
  212.  
  213.  
  214.  
  215.     public void surfaceChanged(SurfaceHolder surfaceholder, int i, int j, int k) {
  216.  
  217.         Log.d(TAG, "surfaceChanged called");
  218.  
  219.     }
  220.  
  221.  
  222.  
  223.     public void surfaceDestroyed(SurfaceHolder surfaceholder) {
  224.  
  225.         Log.d(TAG, "surfaceDestroyed called");
  226.  
  227.     }
  228.  
  229. }
Parsed in 0.044 seconds, using GeSHi 1.0.8.4


this is the java file and XML file given below

Syntax: [ Download ] [ Hide ]
Using xml Syntax Highlighting
  1.  
  2. <?xml version="1.0" encoding="utf-8"?>
  3.  
  4. <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
  5.  
  6.              android:orientation="vertical"
  7.  
  8.              android:layout_width="fill_parent"
  9.  
  10.              android:layout_height="fill_parent"
  11.  
  12.        >
  13.  
  14.       <SurfaceView android:id="@+id/surface"
  15.  
  16.                 android:layout_width="fill_parent"
  17.  
  18.                 android:layout_height="fill_parent">
  19.  
  20.     </SurfaceView>
  21.  
  22.     <LinearLayout
  23.  
  24.            android:orientation="horizontal"
  25.  
  26.            android:layout_height="wrap_content"
  27.  
  28.            android:layout_width="fill_parent"
  29.  
  30.            >
  31.  
  32.         <ImageButton android:id="@+id/play"
  33.  
  34.                     android:layout_height="wrap_content"
  35.  
  36.                     android:layout_width="wrap_content"
  37.  
  38.                     android:src="@drawable/play"/>
  39.  
  40.  
  41.  
  42.         <ImageButton android:id="@+id/pause"
  43.  
  44.                     android:layout_height="wrap_content"
  45.  
  46.                     android:layout_width="wrap_content"
  47.  
  48.                     android:src="@drawable/pause"/>
  49.  
  50.         <ImageButton android:id="@+id/reset"
  51.  
  52.                     android:layout_height="wrap_content"
  53.  
  54.                     android:layout_width="wrap_content"
  55.  
  56.                     android:src="@drawable/reset"/>
  57.  
  58.         <ImageButton android:id="@+id/stop"
  59.  
  60.                     android:layout_height="wrap_content"
  61.  
  62.                     android:layout_width="wrap_content"
  63.  
  64.                     android:src="@drawable/stop"/>
  65.  
  66.     </LinearLayout>
  67.  
  68. </LinearLayout>
  69.  
  70.  
  71.  
  72.  
Parsed in 0.005 seconds, using GeSHi 1.0.8.4



if anybody come across these thing please tell me mistake in the code or if anybody know how play a video file in that android SDKm5 please help me

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

Top

Postby Jesmiatka » Mon May 26, 2008 3:54 pm

Hi,

I am not sure, but you are not preparing your mediaplayer.. You should officially do this before you do mp.start();
If that's not it, you might want to check out this: (I've never tried it but I've put it in my favorites 'cus it looked good back then)


http://davanum.wordpress.com/2007/12/29 ... mote-urls/
Jesmiatka
Senior Developer
Senior Developer
 
Posts: 164
Joined: Mon Feb 04, 2008 3:37 pm
Location: Netherlands

Postby bins1984 » Mon May 26, 2008 7:39 pm

hiiiiiiiiiiii.............


the link u posted is for the old sdk M3 thats working wit that,and that code is not working with the M5,

if u use MediaPlayer.Create(parameter); no need to use prepare(); method....



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

Postby bins1984 » Tue May 27, 2008 10:45 am

hi.....

i played the video file using the Video View,just store the video file in data in the DDMS view and called that file in the program....



but actually i need to play a video file using url or web address can any body knows how to do that,please help me on this topic.

can anybody help me!!!!

by thanks
bins....


this is the code for playing the video file in the emulator

Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1. package com.google.android.musicplayer;
  2.  
  3.  
  4.  
  5. import android.app.Activity;
  6.  
  7. import android.graphics.PixelFormat;
  8.  
  9. import android.os.Bundle;
  10.  
  11. import android.view.View;
  12.  
  13. import android.view.View.OnClickListener;
  14.  
  15. import android.widget.Button;
  16.  
  17. import android.widget.ImageButton;
  18.  
  19. import android.widget.MediaController;
  20.  
  21. import android.widget.VideoView;
  22.  
  23.  
  24.  
  25. public class musicplayer extends Activity {
  26.  
  27.         //private static final String TAG = "VideoPlayer";
  28.  
  29.          private VideoView mPreview;
  30.  
  31.            private ImageButton playButton;
  32.  
  33.            private ImageButton mPause;
  34.  
  35.             private ImageButton mReset;
  36.  
  37.             private ImageButton mStop;
  38.  
  39.         private int i=0;
  40.  
  41.     @Override
  42.  
  43.     public void onCreate(Bundle icicle) {
  44.  
  45.      
  46.  
  47.         super.onCreate(icicle);
  48.  
  49.         getWindow().setFormat(PixelFormat.TRANSPARENT);
  50.  
  51.             setContentView(R.layout.main);
  52.  
  53.          
  54.  
  55.            mPreview = (VideoView)findViewById(R.id.surface);
  56.  
  57.           playButton=(ImageButton)findViewById(R.id.play);
  58.  
  59.           mPause = (ImageButton) findViewById(R.id.pause);
  60.  
  61.           mReset = (ImageButton) findViewById(R.id.reset);
  62.  
  63.           mStop = (ImageButton) findViewById(R.id.stop);
  64.  
  65.          
  66.  
  67.           MediaController nc = new MediaController(this);
  68.  
  69.           mPreview.setMediaController(nc);
  70.  
  71.        //   mPreview.requestFocus();
  72.  
  73.          
  74.  
  75.           playButton.setOnClickListener(new OnClickListener() {
  76.  
  77.              
  78.  
  79.               public void onClick(View arg0) {
  80.  
  81.                   String path = "/data/Crazy.3gp";
  82.  
  83.                   mPreview.setVideoPath(path);
  84.  
  85.                 //  mPreview.requestFocus();
  86.  
  87.                   playButton.requestFocus();
  88.  
  89.                  
  90.  
  91.                                  
  92.  
  93.               }
  94.  
  95.                   });
  96.  
  97.          
  98.  
  99.           mPause.setOnClickListener(new View.OnClickListener() {
  100.  
  101.               public void onClick(View view) {
  102.  
  103.                   if (mPreview != null) {
  104.  
  105.                           if(i==0){
  106.  
  107.                           mPreview.pause();i=1;}
  108.  
  109.                           else{
  110.  
  111.                                   mPreview.start();i=0;
  112.  
  113.                           }
  114.  
  115.                                  
  116.  
  117.                   }
  118.  
  119.               }
  120.  
  121.           });
  122.  
  123.           mReset.setOnClickListener(new View.OnClickListener() {
  124.  
  125.               public void onClick(View view) {
  126.  
  127.                   if (mPreview != null) {
  128.  
  129.                           mPreview.seekTo(0);
  130.  
  131.                   }
  132.  
  133.               }
  134.  
  135.           });
  136.  
  137.           mStop.setOnClickListener(new View.OnClickListener() {
  138.  
  139.               public void onClick(View view) {
  140.  
  141.                   if (mPreview != null) {
  142.  
  143.                           mPreview.stopPlayback();
  144.  
  145.                          
  146.  
  147.                   }
  148.  
  149.               }
  150.  
  151.           });
  152.  
  153.        
  154.  
  155.      
  156.  
  157.      
  158.  
  159.     }
  160.  
  161.    
  162.  
  163. }
Parsed in 0.043 seconds, using GeSHi 1.0.8.4
User avatar
bins1984
Experienced Developer
Experienced Developer
 
Posts: 67
Joined: Fri Feb 08, 2008 8:20 am
Location: India

Postby bins1984 » Thu May 29, 2008 12:30 pm

hello

I tried with VideoView to get access a video file from web,but thats not working.
from media player i am able to connect from url but only hearing audio of that video file,video is not visible.
if any body knows how to play a video player from web...plase help me..

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

Postby Kryten » Wed Jun 18, 2008 12:35 pm

I have got the same problem while trying to play a local Video
here is my code:
Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1.  
  2. Handler handler = new Handler();
  3.  
  4. mediaplayer = MediaPlayer.create(VideoPlayerLocal.this, R.raw.avion);
  5.  
  6.  
  7.  
  8. Runnable r = new Runnable()
  9.  
  10.         {
  11.  
  12.             public void run()
  13.  
  14.             {
  15.  
  16.                 /*try
  17.  
  18.                 {
  19.  
  20.                     mediaplayer.prepare();
  21.  
  22.                 } catch (IOException e)
  23.  
  24.                 {
  25.  
  26.                     // TODO Auto-generated catch block
  27.  
  28.                     Log.e("toto","toto");
  29.  
  30.                 }*/
  31.  
  32.                 mediaplayer.setDisplay(surfaceHolder.getSurface());
  33.  
  34.                 mediaplayer.start();
  35.  
  36.             }
  37.  
  38.         };
  39.  
  40.         handler.post(r);
  41.  
  42.  
Parsed in 0.035 seconds, using GeSHi 1.0.8.4


The problem is: I got the sound but not the image.

I thought that maybe the screen is not refreshing, that is why I used the handler.post method but it seems I was wrong
Kryten
Freshman
Freshman
 
Posts: 2
Joined: Tue Jun 17, 2008 9:36 am

Top

Postby hebbalhrk » Wed Jun 18, 2008 1:00 pm

Try out this one. It worked for me.
I am able to play the 3gp file from the data folder.
To copy 3gp file to data folder, follow steps below
1. start the emulator, allow the emulator to load up.
2.Go to command prompt, rum command
push c:/video.3gp /data/video.3gp
hebbalhrk
Developer
Developer
 
Posts: 37
Joined: Wed Jun 18, 2008 10:35 am

the code below worked fine for 3gp file

Postby hebbalhrk » Wed Jun 18, 2008 1:03 pm

package com.tsys.MultimediaV2;

import java.io.IOException;

import android.app.Activity;
import android.graphics.Color;
import android.graphics.PixelFormat;
import android.media.MediaPlayer;
import android.media.MediaPlayer.OnCompletionListener;
import android.os.Bundle;
import android.util.Log;
import android.view.SurfaceHolder;
import android.view.SurfaceView;
import android.view.View;
import android.widget.ImageButton;

public class MultimediaV2 extends Activity implements SurfaceHolder.Callback {
private static final String TAG = "VideoPlayer";

private MediaPlayer mp;
private SurfaceView mPreview;
private SurfaceHolder holder;
private ImageButton mPlay;
private ImageButton mPause;
private ImageButton mReset;
private ImageButton mStop;

private String path = "/data/video.3gp";

/**
* Called when the activity is first created.
*/
public void onCreate(Bundle icicle) {
super.onCreate(icicle);

setContentView(R.layout.main);

// Set up the play/pause/reset/stop buttons
mPreview = (SurfaceView) findViewById(R.id.surface);
mPlay = (ImageButton) findViewById(R.id.play);
mPause = (ImageButton) findViewById(R.id.pause);
mReset = (ImageButton) findViewById(R.id.reset);
mStop = (ImageButton) findViewById(R.id.stop);

mPlay.setOnClickListener(new View.OnClickListener() {
public void onClick(View view) {
playVideo();

}
});
mPause.setOnClickListener(new View.OnClickListener() {
public void onClick(View view) {
if (mp != null) {
mp.pause();
}
}
});
mReset.setOnClickListener(new View.OnClickListener() {
public void onClick(View view) {
if (mp != null) {
mp.seekTo(0);
}
}
});
mStop.setOnClickListener(new View.OnClickListener() {
public void onClick(View view) {
if (mp != null) {
mp.stop();
mp.release();
}
}
});

// Set the transparency
getWindow().setFormat(PixelFormat.UNKNOWN);


// Set a size for the video screen
holder = mPreview.getHolder();
holder.addCallback(this);
holder.setFixedSize(400,300);

}

private void playVideo() {


mp = new MediaPlayer();
mp.setAudioStreamType(2);

// Set the surface for the video output
mp.setDisplay(mPreview.getHolder().getSurface());

try {
mp.setDataSource(path);
} catch (IllegalArgumentException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}

try {
mp.prepare();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
mp.start();

}

public void surfaceCreated(SurfaceHolder surfaceholder) {
Log.d(TAG, "surfaceCreated called");
//return true;
}

public void surfaceChanged(SurfaceHolder surfaceholder, int i, int j, int k) {
Log.d(TAG, "surfaceChanged called");
}

public void surfaceDestroyed(SurfaceHolder surfaceholder) {
Log.d(TAG, "surfaceDestroyed called");
}

//**************************
public void onPrepared(MediaPlayer mediaplayer) {
Log.d(TAG, "onPrepared called");
}


}
hebbalhrk
Developer
Developer
 
Posts: 37
Joined: Wed Jun 18, 2008 10:35 am

Postby hebbalhrk » Wed Jun 18, 2008 1:17 pm

xml file:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
<SurfaceView android:id="@+id/surface"
android:layout_width="250px"
android:layout_height="250px">
</SurfaceView>
<LinearLayout
android:orientation="horizontal"
android:layout_height="wrap_content"
android:layout_width="fill_parent"
android:padding="10dip"
>
<ImageButton android:id="@+id/play"
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:src="@drawable/play"/>
<ImageButton android:id="@+id/pause"
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:src="@drawable/pause"/>
<ImageButton android:id="@+id/reset"
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:src="@drawable/reset"/>
<ImageButton android:id="@+id/stop"
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:src="@drawable/stop"/>
</LinearLayout>
</LinearLayout>
hebbalhrk
Developer
Developer
 
Posts: 37
Joined: Wed Jun 18, 2008 10:35 am

Postby Kryten » Wed Jun 18, 2008 3:02 pm

I did what you say, it works...
I put it back my way, line by line, to see what was the problem in my code, now my code works too...

I don't understand, but it works, thanks
Kryten
Freshman
Freshman
 
Posts: 2
Joined: Tue Jun 17, 2008 9:36 am

Postby Ashutosh Shukla » Fri Jul 03, 2009 4:10 pm

mp.setDisplay(mPreview.getHolder().getSurface());
This line gives me error please tell me.
In eclipse IDE it says setDisplay requires a SurfaceHolder object which we get on calling getHolder() but on calling the getSurface it gives a Surface so eclipse gives error.
Now if i modify it to
mp.setDisplay(mPreview.getHolder());
Error is removed but i am not getting video displayed. It would be great of someone to get the project zipped and mailed to me at ashu89_shukla@yahoo.com.
I need to get this code working plzzzzzzz.
Ashutosh Shukla
Once Poster
Once Poster
 
Posts: 1
Joined: Thu Jun 11, 2009 6:55 pm

Postby Zerger » Wed Jul 29, 2009 8:27 am

Ashutosh Shukla wrote:mp.setDisplay(mPreview.getHolder().getSurface());
This line gives me error please tell me.
In eclipse IDE it says setDisplay requires a SurfaceHolder object which we get on calling getHolder() but on calling the getSurface it gives a Surface so eclipse gives error.
Now if i modify it to
mp.setDisplay(mPreview.getHolder());
Error is removed but i am not getting video displayed. It would be great of someone to get the project zipped and mailed to me at ashu89_shukla@yahoo.com.
I need to get this code working plzzzzzzz.

you must use the android1.5,try this "mp.setDisplay(mPreview.getHolder());"
Zerger
Freshman
Freshman
 
Posts: 2
Joined: Thu Jun 04, 2009 1:09 pm

not working

Postby judi » Wed Sep 30, 2009 10:40 am

hi bins1984 your code is not working don't know what the problem is.
judi
Freshman
Freshman
 
Posts: 4
Joined: Mon Aug 24, 2009 9:37 am

Re: Not Getting the Video of VideoFile

Postby joby.nk » Fri May 21, 2010 1:19 pm

hi binu i can play video file , i am loding my video file from asset folder
joby.nk
Junior Developer
Junior Developer
 
Posts: 13
Joined: Thu Jan 29, 2009 1:22 pm
Location: INDIA

Re: Not Getting the Video of VideoFile

Postby namrathu1 » Fri May 28, 2010 9:53 am

Hi,
I'm able to see the video view and the buttons but the video is not getting displayed. :( I think i am not placing the 3gp file correctly. I have just placed it in a folder called data. Is that correct? Please let me know.
I have used to code and as per Zerger I'm using 1.5.
Please let me know what mistake i'm doing :(
Thanks in advance
namrathu1
Freshman
Freshman
 
Posts: 5
Joined: Fri May 28, 2010 9:33 am

Top
Next

Return to Multimedia Problems

Who is online

Users browsing this forum: No registered users and 9 guests