3

I'm currently using the Octane.Xamarin.Forms.VideoPlayer to play videos in a Xamarin Forms application, but on Android, the video does not render using the correct aspect ratio, despite trying the various FillMode settings. I want to try to use the MediaElement from the XCT, but have the requirement to play the video from a stream rather than a file on disk, since the media files are encrypted and cannot be read directly. Does anyone know how to use the MediaElement control with a stream providing the video source?

Gerald Versluis
  • 30,492
  • 6
  • 73
  • 100
  • In github source, there is [StreamMediaSource](https://github.com/xamarin/XamarinCommunityToolkit/blob/main/src/CommunityToolkit/Xamarin.CommunityToolkit/Core/StreamMediaSource.shared.cs). You need something like `var mediaStream = new StreamMediaSource(); mediaStream.Stream = ???; myMediaElement.MediaSource = mediaStream;` For `???` - I'm not sure how to turn your stream into what that needs. Definition of `Stream` is `public virtual Func>? Stream`. – ToolmakerSteve Jul 05 '21 at 12:19
  • 1
    So far I've been trying binding the MediaElement control to a MediaSource property that returns this, but when debugging, even though the property is accessed, my stream provider code is not being accessed... return new StreamMediaSource() { Stream = new Func>((cancellationToken) => { return Task.FromResult(this.myStreamProvider); }) }; – Jonathan Websdale Jul 05 '21 at 14:52
  • There must be some un-documented expectation about the state of the stream, or state of the task. Your best bet is to download https://github.com/xamarin/XamarinCommunityToolkit, open it in VS, and search for any references to "StreamMediaSource". If they don't use it internally themselves, I'd say its not working yet. If they do, then hopefully seeing them use it will reveal what is needed. – ToolmakerSteve Jul 05 '21 at 17:25
  • @JonathanWebsdale From [The FillMode / Aspect Ratio doesn't seem to work on Android](https://github.com/adamfisher/Xamarin.Forms.VideoPlayer/issues/3), it is an known issue for VideoPlayer, [Xamarin Community Toolkit MediaElement](https://learn.microsoft.com/en-us/xamarin/community-toolkit/views/mediaelement) don't find any way to load media file by stream. – Cherry Bu - MSFT Jul 06 '21 at 03:22
  • Would appear that 'StreamMediaSource' is not fully implemented in XCT :-( – Jonathan Websdale Jul 08 '21 at 12:10
  • @JonathanWebsdale Maybe, you can also submit a new feature for XCT on github. – Cherry Bu - MSFT Jul 12 '21 at 02:42

0 Answers0