![]() |
VOOZH | about |
dotnet add package Fabulous.MauiControls.MediaElement --version 2.0.0
NuGet\Install-Package Fabulous.MauiControls.MediaElement -Version 2.0.0
<PackageReference Include="Fabulous.MauiControls.MediaElement" Version="2.0.0" />
<PackageVersion Include="Fabulous.MauiControls.MediaElement" Version="2.0.0" />Directory.Packages.props
<PackageReference Include="Fabulous.MauiControls.MediaElement" />Project file
paket add Fabulous.MauiControls.MediaElement --version 2.0.0
#r "nuget: Fabulous.MauiControls.MediaElement, 2.0.0"
#:package Fabulous.MauiControls.MediaElement@2.0.0
#addin nuget:?package=Fabulous.MauiControls.MediaElement&version=2.0.0Install as a Cake Addin
#tool nuget:?package=Fabulous.MauiControls.MediaElement&version=2.0.0Install as a Cake Tool
The MediaElement control is a cross-platform view for playing video and audio. You can find all the details about this control in the .NET MAUI Community Toolkit Media Element documentation.
Please see the HelloMediaElement sample app in this repo to see a working example, or follow the steps below to get up and running with the MediaElement.
1: Add the Fabulous.MauiControls.MediaElement package to your project.
2: Add .UseFabulousMediaElement() to your MauiProgram after .UseFabulousApp().
open Fabulous.MauiControls.MediaElement
type MauiProgram =
static member CreateMauiApp() =
MauiApp
.CreateBuilder()
.UseFabulousApp(App.program)
.UseFabulousMediaElement()
...
.Build()
3: Open Fabulous.MauiControls.MediaElement at the top of the file where you declare your Fabulous program (eg. Program.stateful).
open Fabulous.Maui.MediaElement
The MediaElement uses native media controls under the hood that shouldn't require any additional config i.e. in general you probably won't need to touch AndroidManifest.xml on Android or info.plist on iOS.
However, you will need to make sure that your app has the relevant permissions to access to the source of the media you are planning on playing with the media element. e.g. if you are going to be playing remote media from a url then your app will require permissions to make network requests, but it will most likely have these permissions by default anyway.
MediaElement WidgetNow you can use the MediaElement widget in your Fabulous app as follows:
MediaElement()
.source("https://commondatastorage.googleapis.com/gtv-videos-bucket/sample/BigBuckBunny.mp4")
MediaElement's propertiesYou can access and bind to the MediaElement's properties by using modifiers. E.g. you can set the ShouldAutoPlayproperty to true as follows:
MediaElement()
...
.shouldAutoPlay(true)
widthRequest and heightRequest properties have been renamed width and height in Fabulous, for convenience.MediaElement's eventsTo bind to the MediaElement's events you can also use the corresponding modifiers. E.g. if you'd like to bind to the MediaOpened and OnPositionChanged(Position) events then you can do the following:
type Msg =
| MediaOpened
| PositionChanged of System.TimeSpan
...
MediaElement()
.onMediaEnded(MediaEnded)
.onPositionChanged(fun x -> PositionChanged(x.Position))
MediaElement's methodsTo call the MediaElements's methods (e.g. Play, Pause, etc...) you can use a controller as follows:
let controller = MediaElementController()
let update msg model =
match msg with
...
| VideoPaused -> model, Cmd.none
let pauseVideoCmd () =
async {
do controller.Pause()
return VideoPaused
}
|> Cmd.ofAsyncMsg
...
MediaElement()
.controller(controller)
A full, working example is included in the HelloMediaElement sample project in the /samples directory.
You can access read-only bindable properties of the media element as follows:
let mediaElementRef = ViewRef<MediaElement>()
let update msg model =
| Msg ->
mediaElementRef.Value.Duration // Here you will get the read-only value
model
let view model =
VStack() {
MediaElement(...)
.reference(mediaElementRef)
}
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net7.0 net7.0 is compatible. net7.0-android net7.0-android was computed. net7.0-ios net7.0-ios was computed. net7.0-maccatalyst net7.0-maccatalyst was computed. net7.0-macos net7.0-macos was computed. net7.0-tvos net7.0-tvos was computed. net7.0-windows net7.0-windows was computed. net8.0 net8.0 was computed. net8.0-android net8.0-android was computed. net8.0-browser net8.0-browser was computed. net8.0-ios net8.0-ios was computed. net8.0-maccatalyst net8.0-maccatalyst was computed. net8.0-macos net8.0-macos was computed. net8.0-tvos net8.0-tvos was computed. net8.0-windows net8.0-windows was computed. net9.0 net9.0 was computed. net9.0-android net9.0-android was computed. net9.0-browser net9.0-browser was computed. net9.0-ios net9.0-ios was computed. net9.0-maccatalyst net9.0-maccatalyst was computed. net9.0-macos net9.0-macos was computed. net9.0-tvos net9.0-tvos was computed. net9.0-windows net9.0-windows was computed. net10.0 net10.0 was computed. net10.0-android net10.0-android was computed. net10.0-browser net10.0-browser was computed. net10.0-ios net10.0-ios was computed. net10.0-maccatalyst net10.0-maccatalyst was computed. net10.0-macos net10.0-macos was computed. net10.0-tvos net10.0-tvos was computed. net10.0-windows net10.0-windows was computed. |
This package is not used by any NuGet packages.
This package is not used by any popular GitHub repositories.
| Version | Downloads | Last Updated |
|---|---|---|
| 2.0.0 | 609 | 3/3/2023 |
### Added
- Initial release