Why is it that if I change playVideo to this instead:
private void playVideo(int res, SurfaceHolder holder) {
MediaPlayer mediaplayer = new MediaPlayer();
AssetFileDescriptor afd = null;
try {
afd = this.getAssets().openFd("video1.mpg");
} catch (IOException e1) {
e1.printStackTrace();
}
try {
mediaplayer.setDataSource(afd.getFileDescriptor(),
afd.getStartOffset(), afd.getLength());
mediaplayer.setDisplay(holder);
mediaplayer.prepare();
mediaplayer.start();
// mMediaVideoPlayers.add(mediaplayer);
} catch (IllegalArgumentException e) {
e.printStackTrace();
} catch (IllegalStateException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
}
I get the following exception
W/System.err( 1694): java.io.IOException: Prepare failed.: status=0x1
W/PlayerDriver( 554): PVMFInfoErrorHandlingComplete
However if I change this line
mediaplayer.setDataSource(afd.getFileDescriptor(), afd.getStartOffset
(), afd.getLength());
to
mediaplayer.setDataSource(afd);
I get no exception but still no video.
On Jan 21, 2:33 pm, rukiman <[email protected]> wrote:
> That was how I had it originally, I tried again but still doesn't work
>
> On Jan 21, 2:18 pm, kavitha sunil <[email protected]> wrote:
>
> > try using
>
> > mediaplayer.setDisplay(videoSurfaceHolder[0]);
>
> > On Thu, Jan 21, 2010 at 8:39 AM, rukiman <[email protected]> wrote:
> > > Attached is my code, I cannot see the video while playing a MPG file.
> > > What am I doing wrong here? Thanks.
>
> > > public class VideoTest extends Activity implements
> > > SurfaceHolder.Callback{
>
> > > private ArrayList<MediaPlayer> mMediaVideoPlayers = new
> > > ArrayList<MediaPlayer>();
> > > private SurfaceView videoSurface[] = new SurfaceView[4];
> > > private SurfaceHolder videoSurfaceHolder[] = new SurfaceHolder[4];
>
> > > �...@override
> > > public void onCreate(Bundle savedInstanceState) {
> > > super.onCreate(savedInstanceState);
> > > setContentView(R.layout.main);
> > > videoSurface[0] = (SurfaceView)findViewById(R.id.video1);
> > > videoSurfaceHolder[0] = videoSurface[0].getHolder();
> > > videoSurfaceHolder[0].addCallback(this);
> > > videoSurfaceHolder[0].setType
> > > (SurfaceHolder.SURFACE_TYPE_PUSH_BUFFERS);
> > > }
>
> > > private void playVideo(int res, SurfaceHolder holder) {
> > > MediaPlayer mediaplayer = new MediaPlayer();
> > > AssetFileDescriptor afd = getResources().openRawResourceFd
> > > (res);
> > > try {
> > > mediaplayer.setDataSource(afd.getFileDescriptor(),
> > > afd.getStartOffset(), afd.getLength());
> > > mediaplayer.setDisplay(holder);
> > > mediaplayer.prepare();
> > > mediaplayer.start();
> > > mMediaVideoPlayers.add(mediaplayer);
> > > } catch (IllegalArgumentException e) {
> > > e.printStackTrace();
> > > } catch (IllegalStateException e) {
> > > e.printStackTrace();
> > > } catch (IOException e) {
> > > e.printStackTrace();
> > > }
> > > }
>
> > > public void surfaceChanged(SurfaceHolder holder, int format, int
> > > width, int height) {
> > > }
>
> > > public void surfaceCreated(SurfaceHolder holder) {
> > > playVideo(R.raw.video2, holder);
> > > }
>
> > > public void surfaceDestroyed(SurfaceHolder holder) {
> > > }
> > > }
>
> > > --
> > > You received this message because you are subscribed to the Google
> > > Groups "Android Developers" group.
> > > To post to this group, send email to [email protected]
> > > To unsubscribe from this group, send email to
> > > [email protected]<android-developers%[email protected]>
> > > For more options, visit this group at
> > >http://groups.google.com/group/android-developers?hl=en
--
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en