That did it. Man that was difficult. Thank you so much for your help
Marco. I still have a few problems.
1. the sound won't stop when I hit the back button
2. there are no controls to stop and start the video - guess I gotta
make them
3. video is stretched out
Here is the final code if anyone else want to play video from the raw
folder.
import java.io.IOException;
import android.app.Activity;
import android.media.MediaPlayer;
import android.os.Bundle;
import android.view.SurfaceView;
import android.view.SurfaceHolder;
import android.view.SurfaceHolder.Callback;
import android.content.res.AssetFileDescriptor;
public class myapp extends Activity implements Callback {
public MediaPlayer mp = new MediaPlayer();
public SurfaceView sv = null;
SurfaceHolder holder = null;
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
this.sv = (SurfaceView)findViewById(R.id.SurfaceView01);
this.holder = sv.getHolder();
holder.addCallback(this);
holder.setType(SurfaceHolder.SURFACE_TYPE_PUSH_BUFFERS);
}
@Override
public void surfaceChanged(SurfaceHolder holder, int format, int
width,
int height) {
// TODO Auto-generated method stub
}
@Override
public void surfaceCreated(SurfaceHolder holder) {
// TODO Auto-generated method stub
AssetFileDescriptor afd = getResources().openRawResourceFd
(R.raw.samplevideo);
mp.setDisplay(sv.getHolder());
try {
mp.setDataSource(afd.getFileDescriptor(),
afd.getStartOffset(),
afd.getLength());
mp.prepare();
} catch (IllegalArgumentException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IllegalStateException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
mp.start();
}
@Override
public void surfaceDestroyed(SurfaceHolder holder) {
// TODO Auto-generated method stub
}
}
--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---