Try setting a SurfaceHolder callback and delaying the call to MediaPlayer.setDisplay() until you've gotten the surfaceCreated() callback.
On Fri, Jul 10, 2009 at 11:53 AM, Alslayer<[email protected]> wrote: > > I noticed with all the copying and deleting code I forgot to add > setContentView(R.layout.main);. So now I don't get the "The > application stopped unexpectedly." error anymore. Now the app starts > up with a black screen then goes back the home screen. Here is the > whole code and the xml. > > import java.io.IOException; > import android.app.Activity; > import android.media.MediaPlayer; > import android.os.Bundle; > import android.view.SurfaceView; > import android.content.res.AssetFileDescriptor; > > public class myapp extends Activity { > > /** Called when the activity is first created. */ > �...@override > public void onCreate(Bundle savedInstanceState) { > super.onCreate(savedInstanceState); > setContentView(R.layout.main); > > AssetFileDescriptor afd = getResources().openRawResourceFd > (R.raw.samplevideo); > MediaPlayer mp = new MediaPlayer(); > SurfaceView sv = (SurfaceView)findViewById > (R.id.SurfaceView01); > 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(); > } > } > > > The XML > > <?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/SurfaceView01" > android:layout_width="wrap_content" > android:layout_height="wrap_content"> > </SurfaceView> > > </LinearLayout> > > > --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---

