Forum Xamarin.Forms

Xamarin Forms Video Player

AdamFisherAdamFisher USMember ✭✭

When I was taking classes last year through Xamarin University, I was surprised to find there was no Xamarin Forms video player component in core. So I thought it would be a fun little side project I have been working on for the past few months. I just released it to the Xamarin Component Store. It allows you to hook into events (playing, paused, completed, etc.) and comes with a variety of options for volume, visibility, and arbitrary events for time intervals among other things - all from shared code.

Let me know what you guys think. I hope you find it useful in your projects. I am opening this thread for any discussions related to the component.

Component:
http://go.adams.life/1VQbqnt

Blog Post:
http://www.adams.life/blog/2016/03/cross-platform-video-player-xamarin-forms/

Bug Tracker:
https://bitbucket.org/OctaneSoftware/octane.xam.videoplayer/issues

Posts

  • AdrianKnightAdrianKnight USMember ✭✭✭✭

    Hi,

    Are you using the default video players in each platform? For Android, can you use ExoPlayer and AVPlayer for iOS? I think a cross-platform video player would be great, but I'd rather purchase one with most recent technology. I especially dislike the stock player on Android since it takes a while to load videos.

  • AdamFisherAdamFisher USMember ✭✭
    edited March 2016

    AVPlayer is used for iOS and VideoView is used for Android. I was thinking about ExoPlayer for Android but decided it was out of scope for the initial release. ExoPlayer is more complex to initialize and manage especially when attempting to map it to a cross-platform interface.

    Someone did create an ExoPlayer binding library and that could be used to extend the VideoPlayerRenderer with an ExoPlayer implementation in the interim.

    Thanks for the suggestion. I added it to the issue queue to keep track of it. I would definitely like to implement it at some point to give more options.

    https://bitbucket.org/OctaneSoftware/octane.xam.videoplayer/issues/1/change-the-native-renderer-to-use

  • AdrianKnightAdrianKnight USMember ✭✭✭✭

    @AdamFisher Would be cool to see more advanced functionality. I have yet to figure out how to detect the following on ExoPlayer: https://github.com/martijn00/ExoPlayerXamarin/issues/20 I found ways to do it on iOS, but they seemed quite hacky.

  • AdamFisherAdamFisher USMember ✭✭
    edited April 2016

    ExoPlayer support has been added to the issue queue as a feature request but didn't want to do it for first out since it is only compatible with the newer media framework. The other reason is the unclear alignment between the unified Forms API I am exposing and some of the functionality that ExoPlayer doesn't make readily understandable for mapping it. Long story short, it is on the road map:

    https://bitbucket.org/OctaneSoftware/octane.xam.videoplayer/issues/4/change-the-native-renderer-to-use

    As for your specific situation, you might try overriding the MediaCodecVideoTrackRenderer and creating your own progress changed event listener like they did here:

    http://stackoverflow.com/questions/28590782/android-exoplayer-onprogresschanged

  • DirkWilhelmDirkWilhelm USMember ✭✭✭✭

    @AdamFisher

    i'm very interested in using your component, but i have a question before i buy it:

    when i tried to implement my own videoplayer, i sometimes get an error message on android like this on some user devices when playing local videos:

    java.io.IOException: setDataSourceFD failed.: status=0x80000000
    android.media.MediaPlayer._setDataSource(Native Method)
    android.media.MediaPlayer.setDataSource()MediaPlayer.java:1101
    android.media.MediaPlayer.setDataSource()MediaPlayer.java:1085
    mono.java.lang.RunnableImplementor.n_run(Native Method)
    mono.java.lang.RunnableImplementor.run()RunnableImplementor.java:29
    android.os.Handler.handleCallback()Handler.java:733
    android.os.Handler.dispatchMessage()Handler.java:95
    android.os.Looper.loop()Looper.java:136
    android.app.ActivityThread.main()ActivityThread.java:5590
    java.lang.reflect.Method.invokeNative(Native Method)
    java.lang.reflect.Method.invoke()Method.java:515
    com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run()ZygoteInit.java:1268
    com.android.internal.os.ZygoteInit.main()ZygoteInit.java:1084
    dalvik.system.NativeStart.main(Native Method)
    Xamarin caused by: Java.IO.IOException: setDataSourceFD failed.: status=0x80000000
    System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
    Android.Runtime.JNIEnv.CallVoidMethod(IntPtr jobject, IntPtr jmethod, JValue* parms)
    Android.Media.MediaPlayer.SetDataSource(FileDescriptor fd)
    

    or

    java.io.IOException: Prepare failed.: status=0x1
    android.media.MediaPlayer._prepare(Native Method)
    android.media.MediaPlayer.prepare()MediaPlayer.java:1343
    mono.java.lang.RunnableImplementor.n_run(Native Method)
    mono.java.lang.RunnableImplementor.run()RunnableImplementor.java:29
    android.os.Handler.handleCallback()Handler.java:739
    android.os.Handler.dispatchMessage()Handler.java:95
    android.os.Looper.loop()Looper.java:145
    android.app.ActivityThread.main()ActivityThread.java:6145
    java.lang.reflect.Method.invoke(Native Method)
    java.lang.reflect.Method.invoke()Method.java:372
    com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run()ZygoteInit.java:1399
    com.android.internal.os.ZygoteInit.main()ZygoteInit.java:1194
    Xamarin caused by: Java.IO.IOException: Prepare failed.: status=0x1
    System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
    Android.Runtime.JNIEnv.CallVoidMethod(IntPtr jobject, IntPtr jmethod)
    Android.Media.MediaPlayer.Prepare()
    

    Did you ever see this error using your component?

  • AdamFisherAdamFisher USMember ✭✭

    I have not seen that before. It looks like others have experienced this issue on Android and might have something to do with compatibility of the file encoding. Some devices have more advanced support than others for different codecs. You might try re-encoding your file with officially supported Android media formats to see if that is the culprit.

    Another thing to try is hook into the VideoPlayer.Failed event to see if the native video player reported any additional meta data during the error.

  • TupakTupak ARMember

    Hi Adam!

    Very interesting your component!

    I need to play HLS and DASH streaming in iOS, Android and Windows. Can I do this with your Media Player?

    Thanks!

  • AdamFisherAdamFisher USMember ✭✭

    The default underlying platforms will dictate the streaming protocols supported. I don't think you would get those capabilities on Android by default but you could always use the component and create a native renderer and incorporate ExoPlayer which I believe would give you what you need.

Sign In or Register to comment.