0

I am working on a video streaming application like YouTube. I am using VideoView's built in streaming capability.

I am using Fragments, so on phones there is a Activity wrapper around VideoFragment. The UX should be similar to YouTube's, so in portrait there is video playing at the top and some aditional views below it, etc., and in landscape, all there is is a fullscreen video.

What I have trouble with is orientation changes, what I obviously want is have video continue playing when orientation is changed. As I said, the video is streamed, so just persisting the current video time is not going to cut it. The only way I managed to do that is by forcing to not restart activity with android:configChanges="keyboardHidden|orientation|screenSize" set on the wrapper activity in Manifest.

So this works nicely, but fails when I want to have different layouts for layout and layout-land as YouTube does, because the activity is not restarted, so theres no oportunity for fragment to load new layout as far as I know.

Thanks!

urSus
  • 12,492
  • 12
  • 69
  • 89
  • `theres no oportunity for fragment to load new layout` This can be done, but then, this might be a problem: `so just persisting the current video time is not going to cut it`. – Vikram Sep 04 '13 at 03:29
  • Override `onConfigurationChanged(Configuration)` in your activity. It will be called when an orientation change happens. Create a new Fragment that holds your video viewer and use `FragmentTransaction.replace(int, Fragment)` to switch the fragments. Now, inside `onCreateView()` of this Fragment, you should have an `if-else` statement check for current orientation: `if (getResources().getConfiguration().orientation == Configuration.ORIENTATION_LANDSCAPE) { // inflate landscape view } else { // inflate load portrait }`. I don't think this will solve your problem, but you can give it a try. – Vikram Sep 04 '13 at 03:55
  • but this would destroy the videoview and its buffer right? I might aswell allow it to restart and change layout naturally – urSus Sep 04 '13 at 16:05
  • Like I said in my first comment, `This can be done, but then, this might be a problem: so just persisting the current video time is not going to cut it`: Some useful links: [Android VideoView orientation change with buffered video](http://stackoverflow.com/questions/4434027/android-videoview-orientation-change-with-buffered-video), [Change layout while orientation change at runtime in a fragment without recreating the view](http://stackoverflow.com/questions/14339255/change-layout-while-orientation-change-at-runtime-in-a-fragment-without-recreati). – Vikram Sep 04 '13 at 17:30
  • yea well, the optimal solution would be to have the buffer persist in some retained layoutless fragment or something, which would then pass the buffer to the new videoview, right? – urSus Sep 04 '13 at 18:18
  • @urSus how u resolved your issue i m facing same issue ? – Erum Sep 17 '15 at 16:49

0 Answers0