Discussion Forums  >  Uncategorized

Replies: 3    Views: 328

steveh6883
buzztouch Evangelist
Profile
Posts: 383
Reg: May 15, 2011
Gosport, UK
3,830
06/12/11 02:19 PM (14 years ago)

Audiostream restarting on rotate

Hi All Android BT v1.4 - currently got an app that has audio stream with planned video stream and youtube stream. Testing the app so far am finding that the audio stream (and video stream as I have found in other apps) restarts if the orientation is rotated, don't really want to turn off screen rotate in the code as I want to be able to view video in full landscape, curiously this doesnt happen for youtube stream,just audio & video stream from my own or other webspace & it's really annoying trying to listen to audio or watch streaming video & it restarts stream if orientation is accidentally rotated Anyone any ideas to fix this?
 
David @ buzztouch
buzztouch Evangelist
Profile
Posts: 6866
Reg: Jan 01, 2010
Monterey, CA
78,840
like
06/13/11 04:35 AM (14 years ago)
A few thoughts. In Android, both Streaming Video and Streaming Audio screens use the same Java class file in the Eclipse project. Screen_Video.java is used for both types of media because it fires the devices native media player and this player can handle audio or video. In fact, if my memory serves me right, the 'loading message' reads 'loading video' even when you're loading a audio stream. Funny, it's been on the list for ever! Anyway, this file is an Activity (screens are called activities in Android) and it has several life cycle events. Have a look at the startMovie method, this gets called to start the media. I see in the code that it's starting the media (or re-starting) in the activities onResume() method. I'll bet Android is calling this onResume() method when the device rotates. This means if the media is playing it will re-start, not good! I haven't tinker with this, but you could do some simple tests to see if this assumption is true. The mediaController instance is being created everytime the startMovie method is being called. Sounds to me like the mediaPlayer should only be created when the screen loads, not when the screen 'resumes.' This means the fix could be something as simple as commenting out the mediaController = new MediaController(this) on line 120. like this... //mediaController = new MediaController(this) This should work because the mediaController is being created in the onCreate() method of the activity (see line 48 in this same file). I'm scrathing my head a bit as to why it would be betting re-created again in the startMovie method, doesn't seem right. There may be a reason I'm not thinking of but it does seem like you could comment out that line in the startMovie method and see what happens. If you can test any of this, awesome, re-post your findings. If it's totally over-your-head, OK, no worries. Post the URL to the audio file your streaming and I'll see what I can come up with here.
 
Intrege
Veteran developer
Profile
Posts: 196
Reg: Sep 12, 2011
Philadelphia, P...
3,160
like
11/13/11 06:58 PM (14 years ago)
Hey David. Was this ever looked back into? I am not seeing the controller on that line anymore. Of course their has been may updates since then. Just wondering if it's still a quick fix not to not have the screen change orientation? Thanks in advance.
 
Intrege
Veteran developer
Profile
Posts: 196
Reg: Sep 12, 2011
Philadelphia, P...
3,160
like
11/13/11 07:28 PM (14 years ago)
Nevermine. Found the answer. Thanks
 

Login + Screen Name Required to Post

pointerLogin to participate so you can start earning points. Once you're logged in (and have a screen name entered in your profile), you can subscribe to topics, follow users, and start learning how to make apps like the pros.