3

A question like this is already posted but in my situation, there is some difference. I have different layout design for landscape and portrait modes (both modes have VideoView) of the fragment that's why I can not use configChanges as below:

android:configChanges="screenSize|orientation|keyboardHidden"

Now when I rotate everything recreate. I tried retainState/saveInstanceState but does not get success.

I want my video to play continuously without stopping like YouTube app.

Any help would be appreciated.

TofferJ
  • 4,678
  • 1
  • 37
  • 49
Shadik Khan
  • 1,217
  • 1
  • 8
  • 18

1 Answers1

1

If you are using the MediaPlayer classes for video playback I would suggest against doing so. YouTube app uses a library called ExoPlayer that is far superior in terms of video support on Android devices. It is a little harder to get setup and operating but once it is that success in playing videos across all the android devices is much better.

That being said. You will still need to stop the video and resume playing at that specific time frame. The best way to do this would be to get the timestamp on rotation and once the surface being played to is ready again (onSurfaceCreateed or onSurfaceChanged events if using the ExoPlayer library) start the video again at that time stamp.

Ahmed Alnabhan
  • 608
  • 1
  • 9
  • 13
Devsil
  • 598
  • 3
  • 16
  • 1
    FWIW, it's possible to do -- see "double decode" in Grafika (https://github.com/google/grafika) for an example -- but it does get complicated. – fadden Oct 06 '15 at 15:49
  • Oh very nice. I had not seen that and wasn't aware. Thank you very much for the link to that. Its always nice to be made aware of a new technique. – Devsil Oct 06 '15 at 15:52
  • @fadden Grafika projects needs minimum 18 level API. what about lower I need from level 15. – Shadik Khan Oct 07 '15 at 06:36
  • If you need a lower API support you will have to implement your own solution that would work for that API. Best suggestion I can give you would be to look at the source and try to reverse engineer it as best as possible with supported items. – Devsil Oct 07 '15 at 14:49
  • @Sadiq The key class (TextureView) was added in API 14. You won't be able to use MediaCodec, but it's possible to send MediaPlayer output to a Surface (also as of API 14). – fadden Oct 07 '15 at 15:03