Plugin.MediaManager
1.2.2
Requires NuGet 2.14 or higher.
dotnet add package Plugin.MediaManager --version 1.2.2
NuGet\Install-Package Plugin.MediaManager -Version 1.2.2
<PackageReference Include="Plugin.MediaManager" Version="1.2.2" />
<PackageVersion Include="Plugin.MediaManager" Version="1.2.2" />
<PackageReference Include="Plugin.MediaManager" />
paket add Plugin.MediaManager --version 1.2.2
#r "nuget: Plugin.MediaManager, 1.2.2"
#:package Plugin.MediaManager@1.2.2
#addin nuget:?package=Plugin.MediaManager&version=1.2.2
#tool nuget:?package=Plugin.MediaManager&version=1.2.2
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
Status:
Support
- 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: hello@baseflow.com
- Powered by: baseflow.com
Wiki
More documenatation and information is available on the Wiki
Blogs
Installation
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
Platform Support
| Platform | Supported | Version | Player |
|---|---|---|---|
| .Net Standard | Yes | 2.0+ | MediaManager |
| Xamarin.Forms | Yes | 3.2+ | MediaManager |
| Xamarin.Android | Yes | API 16+ | ExoPlayer |
| Xamarin.iOS | Yes | iOS 10+ | AVPlayer |
| Xamarin.Mac | Yes | 3.0+ | AVPlayer |
| Xamarin.tvOS | Yes | 10.0+ | AVPlayer |
| Tizen | Yes | 4.0+ | MediaPlayer |
| Windows 10 UWP | Yes | 10+ | MediaPlayer |
| Windows WPF (.NET Framework) | Yes | 4.7.2+ | MediaPlayer |
| Windows WPF (.NET Core) | Yes | 3.1+ | MediaPlayer |
Usage
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.
CrossMediaManager.Current.Init();
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.
public class MainActivity : AppCompatActivity
{
protected override void OnCreate(Bundle savedInstanceState)
{
base.OnCreate(savedInstanceState);
SetContentView(Resource.Layout.main_activity);
CrossMediaManager.Current.Init(this);
}
}
When tapping the notification, it will launch your activity with an intent. In most cases, you probably want to set LaunchMode on your Activity to SingleTop.
That should bring your app back into focus when tapped. You can read more about it here
[Activity(LaunchMode = LaunchMode.SingleTop)]
public class MainActivity : AppCompatActivity
If you want to handle when the app is opened via a notification tap, you can override OnNewIntent on your activity:
protected override void OnNewIntent(Intent intent)
{
base.OnNewIntent(intent);
// TODO: Handle app opened from notification tap.
}
Disposing
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
//Audio
await CrossMediaManager.Current.Play("https://ia800806.us.archive.org/15/items/Mp3Playlist_555/AaronNeville-CrazyLove.mp3");
//Video
await CrossMediaManager.Current.Play("http://clips.vorwaerts-gmbh.de/big_buck_bunny.mp4");
Play multiple media items
public IList<string> Mp3UrlList => new[]{
"https://ia800806.us.archive.org/15/items/Mp3Playlist_555/AaronNeville-CrazyLove.mp3",
"https://ia800605.us.archive.org/32/items/Mp3Playlist_555/CelineDion-IfICould.mp3",
"https://ia800605.us.archive.org/32/items/Mp3Playlist_555/Daughtry-Homeacoustic.mp3",
"https://storage.googleapis.com/uamp/The_Kyoto_Connection_-_Wake_Up/01_-_Intro_-_The_Way_Of_Waking_Up_feat_Alan_Watts.mp3",
"https://aphid.fireside.fm/d/1437767933/02d84890-e58d-43eb-ab4c-26bcc8524289/d9b38b7f-5ede-4ca7-a5d6-a18d5605aba1.mp3"
};
await CrossMediaManager.Current.Play(Mp3UrlList);
Other play possibilities
Task<IMediaItem> Play(IMediaItem mediaItem);
Task<IMediaItem> Play(string uri);
Task<IMediaItem> Play(IEnumerable<IMediaItem> items);
Task<IMediaItem> Play(IEnumerable<string> items);
Task<IMediaItem> Play(FileInfo file);
Task<IMediaItem> Play(DirectoryInfo directoryInfo);
Task<IMediaItem> PlayFromAssembly(string resourceName, Assembly assembly = null);
Task<IMediaItem> PlayFromResource(string resourceName);
- Playing from a
Filecan be done for example by using theFileandDirectoryapi'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