locked
Video Playback with Rotation issues RRS feed

  • Question

  • User250320 posted

    I'm having an odd issue with video playback. In portrait mode everything works fine with the video taking up a spot on a fragment like so:

    <?xml version="1.0" encoding="utf-8"?> <ScrollView xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="fill_parent" android:layout_height="wrap_content" android:padding="10dp" android:orientation="vertical" android:gravity="center_horizontal" android:fillViewport="false"> <LinearLayout android:orientation="vertical" android:layout_width="fill_parent" android:layout_height="wrap_content"> <TextView android:textAppearance="?android:attr/textAppearanceLarge" android:layout_width="match_parent" android:layout_height="wrap_content" android:id="@+id/tvLessonName" android:text="@string/Lesson" android:layout_gravity="center_horizontal" /> <TextView android:text="Small Text" android:textAppearance="?android:attr/textAppearanceSmall" android:layout_width="match_parent" android:layout_height="wrap_content" android:id="@+id/tvLessonDescription" /> <VideoView android:layout_width="fill_parent" android:layout_height="300dp" android:id="@+id/vvLessonPlayback" android:keepScreenOn="true" /> </LinearLayout> </ScrollView>

    Video plays back and all is right with the world. However if the user rotates the device, the screen goes black and the video stops playing.

    So I created a second layout in layout-land for the video that has a simple layout like this loaded in a fragment:

    <LinearLayout<del></del> xmlns:android="http://schemas.android.com/apk/res/android" android:orientation="horizontal" android:layout_width="fill_parent" android:layout_height="fill_parent"> <VideoView android:layout_width="fill_parent" android:layout_height="fill_parent" android:id="@+id/vvLessonPlayback" android:keepScreenOn="true" /> </LinearLayout>

    SetVideoURI is done in the OnCreateView and it is started in the OnStart and Stopped in the OnStop. When the rotation happens OnStop is called but onstart is never called again. If I change to landscape and then navigate to the fragment it again plays fine but rotation to portrait causes the same problem. (and it appears that my landscape layout isn't being used)

    The documentation for video playback is weak to say the least. Any guidance on how to get a video playing inline in a fragment in portrait view and then full screen when rotated landscape, which I believe is the most common usage anyhow would be greatly appreciated.

    Thursday, November 17, 2016 1:27 PM

Answers

  • User145650 posted

    @JamesHancock.1360

    Use this code for Cross-Platform Video player for Xamarin forms. Working for Android and iOS

    https://github.com/Patil2421/Components/tree/XAMARIN-CROSS-PLATFORM-VIDEO-PLAYER

    Tell me if any issues.

    • Marked as answer by Anonymous Thursday, June 3, 2021 12:00 AM
    Thursday, January 12, 2017 11:31 AM

All replies

  • User145650 posted

    @JamesHancock.1360

    Use this code for Cross-Platform Video player for Xamarin forms. Working for Android and iOS

    https://github.com/Patil2421/Components/tree/XAMARIN-CROSS-PLATFORM-VIDEO-PLAYER

    Tell me if any issues.

    • Marked as answer by Anonymous Thursday, June 3, 2021 12:00 AM
    Thursday, January 12, 2017 11:31 AM
  • User250320 posted

    Thanks! Appears to work!

    Thursday, January 12, 2017 12:56 PM