Have you read this?: http://developer.android.com/intl/de/resources/articles/faster-screen-orientation-change.html
On Mar 8, 11:19 am, Chronos <[email protected]> wrote: > Hi Martin, > > I am not sure if this is the problem, but you should not keep > instances to the old activity during configuration change at all > (MediaPlayer is created with a Context); think about initializing and > managing the MediaPlayer in your Application class or a background > service, if you want it to survive configuration changes. > > Have fun > > On Feb 16, 1:24 pm, Martin Nilsson <[email protected]> wrote: > > > It seems that my media player object is somehow destroyed when I use > > onRetainNonConfigurationInstance. I when I catch the object in > > "createMediaPlayer" below I can verify that mp != null. But when I try > > to get the current position with mp.getCurrentPosition() I get an > > exception and the activity shuts down. I can see the following in the > > log: > > > 02-16 10:45:55.869: DEBUG/StreamingPlayer(1854): restoreMediaPlayer > > 02-16 10:45:55.879: DEBUG/AndroidRuntime(1854): Shutting down VM > > 02-16 10:45:55.879: WARN/dalvikvm(1854): threadid=3: thread exiting > > with uncaught exception (group=0x4000fe70) > > 02-16 10:45:55.889: ERROR/AndroidRuntime(1854): Uncaught handler: > > thread main exiting due to uncaught exception > > 02-16 10:45:55.919: ERROR/AndroidRuntime(1854): > > java.lang.RuntimeException: Unable to start activity > > ComponentInfo{com.stericsson.streamingplayer/ > > com.stericsson.streamingplayer.StreamingPlayer}: > > java.lang.IllegalStateException > > 02-16 10:45:55.919: ERROR/AndroidRuntime(1854): at > > android.app.ActivityThread.performLaunchActivity(ActivityThread.java: > > 2268) > > 02-16 10:45:55.919: ERROR/AndroidRuntime(1854): at > > android.app.ActivityThread.handleLaunchActivity(ActivityThread.java: > > 2284) > > 02-16 10:45:55.919: ERROR/AndroidRuntime(1854): at > > android.app.ActivityThread.handleRelaunchActivity(ActivityThread.java: > > 3278) > > 02-16 10:45:55.919: ERROR/AndroidRuntime(1854): at > > android.app.ActivityThread.access$1900(ActivityThread.java:112) > > 02-16 10:45:55.919: ERROR/AndroidRuntime(1854): at > > android.app.ActivityThread$H.handleMessage(ActivityThread.java:1696) > > 02-16 10:45:55.919: ERROR/AndroidRuntime(1854): at > > android.os.Handler.dispatchMessage(Handler.java:99) > > 02-16 10:45:55.919: ERROR/AndroidRuntime(1854): at > > android.os.Looper.loop(Looper.java:123) > > 02-16 10:45:55.919: ERROR/AndroidRuntime(1854): at > > android.app.ActivityThread.main(ActivityThread.java:3948) > > 02-16 10:45:55.919: ERROR/AndroidRuntime(1854): at > > java.lang.reflect.Method.invokeNative(Native Method) > > 02-16 10:45:55.919: ERROR/AndroidRuntime(1854): at > > java.lang.reflect.Method.invoke(Method.java:521) > > 02-16 10:45:55.919: ERROR/AndroidRuntime(1854): at > > com.android.internal.os.ZygoteInit > > $MethodAndArgsCaller.run(ZygoteInit.java:782) > > 02-16 10:45:55.919: ERROR/AndroidRuntime(1854): at > > com.android.internal.os.ZygoteInit.main(ZygoteInit.java:540) > > 02-16 10:45:55.919: ERROR/AndroidRuntime(1854): at > > dalvik.system.NativeStart.main(Native Method) > > 02-16 10:45:55.919: ERROR/AndroidRuntime(1854): Caused by: > > java.lang.IllegalStateException > > 02-16 10:45:55.919: ERROR/AndroidRuntime(1854): at > > android.media.MediaPlayer.getCurrentPosition(Native Method) > > 02-16 10:45:55.919: ERROR/AndroidRuntime(1854): at > > com.stericsson.streamingplayer.StreamingPlayer.restoreMedidaPlayer(StreamingPlayer.java: > > 233) > > 02-16 10:45:55.919: ERROR/AndroidRuntime(1854): at > > com.stericsson.streamingplayer.StreamingPlayer.createMediaPlayer(StreamingPlayer.java: > > 155) > > 02-16 10:45:55.919: ERROR/AndroidRuntime(1854): at > > com.stericsson.streamingplayer.StreamingPlayer.onCreate(StreamingPlayer.java: > > 94) > > 02-16 10:45:55.919: ERROR/AndroidRuntime(1854): at > > android.app.Instrumentation.callActivityOnCreate(Instrumentation.java: > > 1123) > > 02-16 10:45:55.919: ERROR/AndroidRuntime(1854): at > > android.app.ActivityThread.performLaunchActivity(ActivityThread.java: > > 2231) > > 02-16 10:45:55.919: ERROR/AndroidRuntime(1854): ... 12 more > > > The code which gives the print " restoreMediaPlayer" is located in > > function "createMediaPlayer" which I provided in my previous post. > > > Why can't I pass trough the media player object when I can send > > variables just fine? Could it be that I need to create a new thread? > > When I start the media player the first time it looks like this in the > > code: > > > Runnable r = new Runnable() { > > public void run() { > > setDataSource(path); > > prepare(); > > start(); > > } > > }; > > new Thread(r).start(); > > > But I wasn't able to reuse the code after orientation change, I still > > had my activity crashing. > > > Regards > > > Martin > > > On 15 Feb, 13:46, Martin Nilsson <[email protected]> wrote: > > > > Hello, > > > > I am trying to keep a video playback going after a orientation change > > > but keep getting a crash when trying to pass the media player trough > > > onRetainNonConfigurationInstance. > > > > I can pass the time, setup the media player from scratch and do a fast > > > forward but I would not like to do the setup more than once. > > > > My code looks like: > > > > @Override > > > public Object onRetainNonConfigurationInstance() { > > > return( mp ); > > > } > > > > public void onCreate(Bundle icicle) { > > > ... > > > createMediaPlayer(); > > > > } > > > > public void createMediaPlayer() { > > > ... > > > if (getLastNonConfigurationInstance()!=null) { > > > mp = (MediaPlayer)getLastNonConfigurationInstance() ; > > > } else { > > > mp = new MediaPlayer(); > > > ... > > > } > > > > } > > > > Can anyone help me pinpoint why this does not work? -- 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

