System.IO.Stream support for MediaElement #1227
Replies: 6 comments 3 replies
-
Agreed! Any idea for the implementation? |
Beta Was this translation helpful? Give feedback.
-
Well, I know in the WinMediaSource you can create a media source from a stream, so I think focusing on expanding the MediaSource element would be a start. I think the Media Manager would need to be genericize though I'm not too familiar with Tizen and macOS so would need to do some research on the available APIs. |
Beta Was this translation helpful? Give feedback.
-
@brminnick I think there's going to be a need to implement a custom stream per platform for the source. We could probably abstract this by using a wrapper class to implement the platform specific media stream for System.IO.Stream so users don't have to implement it every time for new projects. I actually kind of like this as this allows the user to implement a custom implementation for the stream. For example, remotely accessing content files or streaming via transports like SRT or RTMP can be abstracted. I think as long as the stream is in the format of EBML or BMFF then it should work in theory. This could be done utilizing something like the // Shared implementation - MediaStream.shared.cs
public abstract partial class MediaStream
{
public abstract Task InitializeAsync();
}
// Windows implementation - MediaStream.windows.cs
partial class MediaStream : IRandomAccessStream
{
public abstract bool CanRead { get; }
public abstract bool CanWrite { get; }
public abstract ulong Position { get; }
public abstract ulong Size { get; set; }
public abstract IRandomAccessStream CloneStream();
public void Dispose()
{
Dispose(true);
GC.SuppressFinalize(this);
}
protected abstract void Dispose(bool disposing);
public abstract IAsyncOperation<bool> FlushAsync();
public abstract IInputStream GetInputStreamAt(ulong position);
public abstract IOutputStream GetOutputStreamAt(ulong position);
public abstract IAsyncOperationWithProgress<IBuffer, uint> ReadAsync(IBuffer buffer, uint count, InputStreamOptions options);
public abstract void Seek(ulong position);
public abstract IAsyncOperationWithProgress<uint, uint> WriteAsync(IBuffer buffer);
}
// Android Implementation - MediaStream.android.cs
partial class MediaStream { }
// Android Implementation - MediaStream.tizen.cs
partial class MediaStream { }
// Android Implementation - MediaStream.macios.cs
partial class MediaStream { }
// Media Source - StreamMediaSource.shared.cs
public sealed class StreamMediaSource : MediaSource
{
public static readonly BindableProperty ContentTypeProperty
= BindableProperty.Create(nameof(ContentType), typeof(string), typeof(StreamMediaSource), propertyChanged: OnContentTypeChanged);
public static readonly BindableProperty StreamProperty
= BindableProperty.Create(nameof(Stream), typeof(MediaStream), typeof(StreamMediaSource), propertyChanged: OnStreamSourceChanged);
public MediaStream? Stream
{
get => (MediaStream?)GetValue(StreamProperty);
set => SetValue(StreamProperty, value);
}
public string? ContentType
{
get => (string?)GetValue(ContentTypeProperty);
set => SetValue(ContentTypeProperty, value);
}
static void OnStreamSourceChanged(BindableObject bindable, object oldValue, object newValue) =>
((StreamMediaSource)bindable).OnSourceChanged();
static void OnContentTypeChanged(BindableObject bindable, object oldValue, object newValue) =>
((StreamMediaSource)bindable).OnSourceChanged();
} |
Beta Was this translation helpful? Give feedback.
-
@brminnick Unfortunately, I was misled 😢, the If you pull down my fork on I'll will look into implementing the other platforms though I'm going to be limited on testing as I am a windows baby lol. |
Beta Was this translation helpful? Give feedback.
-
Closed as per the Community Stand-up discussion here: https://youtu.be/N9wMcBP4jtg?t=2889 |
Beta Was this translation helpful? Give feedback.
-
I made a working "hack-around" for this. My approach involves creating a simple ![]() The commit code can be found here. (If you found it useful, please consider adding a star 🙂 ) Beware that you also have to modify AndroidManifest and plist to allow streaming from HTTP source (which in this case is localhost) |
Beta Was this translation helpful? Give feedback.
-
It would be nice if it were possible to reference streams directly in the Media Element with a specified Media Type or by provide a custom Media Source. I have a particular use case where I built a .NET SRT server and client for live streaming.
I'm wondering if this feature would be possible or if there would be limitations of the underlying native media player the element is wrapping?
Beta Was this translation helpful? Give feedback.
All reactions