MediaManager - Cross platform media plugin for Xamarin and Windows
- Designed to be simple and easy to use
- Native playback of media files from remote http(s), embedded and local sources
- Native media notifications and remote controls
- Queue and playback management by default
- Playback status (Playing, Buffering, Loading, Paused, Progress)
- Events for media handling to hook into
- Feel free to open an issue. Make sure to use one of the templates!
- Commercial support is available. Integration with your app or services, samples, feature request, etc. Email: [email protected]
- Powered by: baseflow.com
More documenatation and information is available on the Wiki
- Xamarin Blog
- Baseflow Blog
Add the NuGet package to all the projects you want to use it in.
- In Visual Studio - Tools > NuGet Package Manager > Manage Packages for Solution
- Select the Browse tab, search for MediaManager
- Select Plugin.MediaManager
- Install into each project within your solution
|Windows 10 UWP||Yes||10+||MediaPlayer|
|Windows WPF (.NET Framework)||Yes||4.7.2+||MediaPlayer|
|Windows WPF (.NET Core)||Yes||3.1+||MediaPlayer|
Call MediaManager.Current from any .Net library or Xamarin project to gain access to APIs.
IMPORTANT: Initialize plugin
Make sure to call Init() in all the native platforms on startup of your app.
Optionally provide the
Activity on Android. This will also be used to bind the Android
Service and will be used as
Intent to launch from a notification.
When tapping the notification, it will launch your activity with an intent. In most cases, you probably want to set
LaunchMode on your
That should bring your app back into focus when tapped. You can read more about it here
If you want to handle when the app is opened via a notification tap, you can override
OnNewIntent on your activity:
The player can be disposed via
CrossMediaManager.Current.Dispose(). Make sure to call
CrossMediaManager.Current.Init() if you used dispose before playing another media file.
Play a single media item
Play multiple media items
Other play possibilities
- Playing from a
Filecan be done for example by using the
Directoryapi's. You download a file from the internet and save it somewhere using these .NET api's.
- When playing from
Assemblyyou need to add a media file to a assembly and set the build action to
- When playing from a
Resourceyou should add your media file for example to the
rawfolder on Android, and the
Resourcesfolder on iOS.
Control the player
Control the Queue
Retrieve and set information
Properties available on CrossMediaManager.Current.MediaPlayer.*
Hook into events
Retrieve metadata for media
Depending on the platform and the media item metadata will be extracted from ID3 data in the file.
Since the metadata might not be available immediately you can subscribe for updates like this:
Alternatively you could also use the
PropertyChanged event to see updates to the metadata.
You can also get a single frame from a video:
Add Video Player to the UI
The video view will automatically be attached to the player. If you have multiple video views and you want to hook it up yourself do:
After that you can manually add the video view like this:
For android we need a
VideoView in the axml layout.
Then find the view in code:
For iOS, MacOS or tvOS we need to add a
VideoView either in code, or in a Xib or Storyboard.
Then for all platforms we have to add the player view to the
Play a non standard format like HLS, Dash or SS
MediaManager will try to make a guess which media type or format is used. Sometimes this will not be picked up or be wrong, but you can enforce it by setting it yourself like this:
By enforcing it there is still no guarantee that the native system actually is able to play the item.
Platform specific features
|Feature||Android||iOS, Mac, tvOS||UWP||Tizen||WPF|
You can also directly access the native platform implementation if you need it!
VideoView to a Page in Forms is easy as this:
Your Xamarin.Forms page could look like this:
You can even use the normal
Play(object) method and not set source. When you navigate to the view that contains the
VideoView, the player will automatically attach to the view.
If you want a Page that contains a player you can open the
Add the Reactive NuGet package to all the projects you want to use it in.
FFmpegMediaMetadataRetriever on Android
If you want to use FFmpegMediaMetadataRetriever on Android to extract the metadata you can set to use this extension like this:
Intercept share requests from the native platform or other apps
- This library will automatically request the following permissions:
WakeLock. You do not need to add them to your AndroidManifest.
- Your app must target Android SDK v28 or higher
- This library uses ExoPlayer for video playback. This requires that you enable the following
- Dex tool to D8:
- Optional enable R8 Linker to make code smaller:
- Aapt2 build tools:
- Disable multi-dex when using D8 and R8 with AAPT2. Your code should be small enough with those.
In order for the audio to contiunue to play in the background you have to add the 'Audio, Airplay and Picture in Picture Background mode' and 'Background fetch' to your Info.plist
If you are playing audio from a http resource you have to take care of ATS. Optionally you can disable this for playing media. Add the following to your info.plist:
If you want to disable more you could add:
NSAllowsLocalNetworking or even
NSAllowsArbitraryLoads to disable all checks.
- If you want to display a artwork/cover that is embedded into an MP3 file, make sure that you use ID3 v2.3 (not v2.4).
- In the Package.appxmanifest under capabilities you need to select: "Background Media Playback", "Internet"
- Optionally add "Music Library" and "Videos Library" as well if you use that
- You must request
Building the source code
- On Windows you need Visual Studio 2019 with the latest Xamarin, .NET Core, UWP and Windows 10 SDK installed.
- On Visual Studio for Mac 2019 multi-target is not supported. Therefor you need to compile from command line on a Mac. Simple go to the folder where the source code is and run:
msbuild MediaManager.sln /t:rebuildto make a release build run:
msbuild MediaManager.sln /t:rebuild /p:Configuration=Release. To restore your nuget packages run:
msbuild MediaManager.sln /t:restore.