martijn00/XamarinMediaManager


Cross platform Xamarin plugin to play and control Audio and Video

https://baseflow.com

License: MIT

Language: C#

Keywords: audio, media, mediamanager, netstandard, nuget, video, xamarin


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:

Build status GitHub tag NuGet MyGet

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+ MediaElement
Windows WPF No

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

More information on the Xamarin Blog

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.

public class MainActivity : AppCompatActivity
{
	protected override void OnCreate(Bundle savedInstanceState)
	{
		base.OnCreate(savedInstanceState);
		SetContentView(Resource.Layout.main_activity);

		CrossMediaManager.Current.Init(this);
	}
}

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);

Retrieve metadata for media

Depending on the platform and the media item metadata will be extracted from ID3 data in the file.

CrossMediaManager.Current.MediaQueue.Current.Title;
CrossMediaManager.Current.MediaQueue.Current.AlbumArt;
CrossMediaManager.Current.MediaQueue.Current.*

Add Video Player to the UI

For android we need a videoview

playerView = view.FindViewById<VideoView>(Resource.Id.exoplayerview_activity_video);

For iOS we need to add a VideoView either in code, or in a Xib or Storyboard.

var playerView = new VideoView();
View.AddSubview(playerView);

Then for both android and iOS we have to add the player view to the mediaplayer

CrossMediaManager.Current.MediaPlayer.SetPlayerView(playerView);

Control the player

await CrossMediaManager.Current.Play();
await CrossMediaManager.Current.Pause();
await CrossMediaManager.Current.Stop();

await CrossMediaManager.Current.StepForward();
await CrossMediaManager.Current.StepBackward();

await CrossMediaManager.Current.SeekToStart();
await CrossMediaManager.Current.SeekTo(TimeSpan position);

Control the Queue

await CrossMediaManager.Current.PlayPrevious();
await CrossMediaManager.Current.PlayNext();
await CrossMediaManager.Current.PlayPreviousOrSeekToStart();

Retrieve information

CrossMediaManager.Current.MediaPlayer.State == MediaPlayerState.Playing;

Hook into events

event StateChangedEventHandler StateChanged;
event PlayingChangedEventHandler PlayingChanged;
event BufferingChangedEventHandler BufferingChanged;
event MediaItemFinishedEventHandler MediaItemFinished;
event MediaItemChangedEventHandler MediaItemChanged;
event MediaItemFailedEventHandler MediaItemFailed;
event PositionChangedEventHandler PositionChanged;

Xamarin.Forms

await CrossMediaManager.Current.*

Platform specific features

Feature Android iOS, Mac, tvOS UWP Tizen
Audio x x x x
Video x x x x
Queue x x x x
Notifications x x x x
Volume x x x x
Media Extraction x x x x
HLS x x
DASH x
SmoothStreaming x
ChromeCast x
Airplay x
Xamarin.Forms x x x

You can also directly access the native media player if you need it!

//Access ExoPlayer on Android
CrossMediaManager.Android.NativeMediaPlayer.Player.VideoDecoderCounters
CrossMediaManager.Android.*
//iOS, MacOS or tvOS
CrossMediaManager.Apple.*
//UWP
CrossMediaManager.Windows.*
//Tizen
CrossMediaManager.Tizen.*

Building the source code

  • On Windows you need Visual Studio 2019 with the latest Xamarin, .NET Core and UWP 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:rebuild /p:Configuration=Release

IMPORTANT

Android:

  • You must request AccessWifiState, Internet, ForegroundService and WakeLock permissions
  • Your app must target Android SDK v28 or higher

iOS:

  • 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.
  • 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).

Tizen:

  • You must request http://tizen.org/privilege/internet, http://tizen.org/privilege/mediastorage, and http://tizen.org/privilege/externalstorage privileges

Project Statistics

Sourcerank 12
Repository Size 7.37 MB
Stars 356
Forks 203
Watchers 45
Open issues 48
Dependencies 19
Contributors 25
Tags 18
Created
Last updated
Last pushed

Top Contributors See all

Martijn van Dijk Felix Schoeler Erlend Angelsen paulppn Joe Martinez Casper Skoubo Mike Rowley Simon Schick Philipp Tischhauser sjoerd0301 Jonas BtrJay Tomasz Cielecki Michael Dan Siegel escamoteur Brandon Minnick Andrei Nick Randolph John Thiriet

Packages Referencing this Repo

Plugin.MediaManager.Forms
Cross platform Xamarin plugin to play and control Audio and Video
Latest release 0.5.9 - Updated - 356 stars
Plugin.MediaManager
Cross platform Xamarin plugin to play and control Audio and Video
Latest release 0.5.9 - Updated - 356 stars
MediaManager.Unofficial.Reactive
Package Description
Latest release 1.0.2 - Published - 356 stars
MediaManager.Unofficial.Forms
Package Description
Latest release 1.0.2.1 - Updated - 356 stars
MediaManager.Unofficial
Package Description
Latest release 1.0.2 - Published - 356 stars
Plugin.MediaManager.Reactive
Reactive extensions for the MediaManager plugin
Latest release 0.4.5 - Updated - 356 stars
Youscribe.Plugin.MediaManager
Customized XamarinMediaManager
This package is no longer available on NuGet
Plugin.MediaManager.ExoPlayer
ExoPlayer supports more advanced video and audio playback. This is based on the MediaManager plugin
Latest release 0.4.5 - Updated - 356 stars
Xam.Plugin.MediaManager
Cross platform Xamarin plugin to play Media from PCL. Currently only supports audio playback on A...
Latest release 0.0.1 - Published - 356 stars
MediaManager.Unofficial.ExoPlayer
Package Description
Latest release 1.0.2 - Published - 356 stars

Recent Tags See all

0.5.9 May 19, 2019
0.5.1 April 13, 2019
0.5.0 April 11, 2019
0.4.4 August 21, 2017
0.4.3 July 28, 2017
0.4.3 July 28, 2017
0.4.2 July 28, 2017
0.4.2 July 28, 2017
0.4.0 March 17, 2017
0.3.3 February 21, 2017
0.3.2 February 20, 2017
0.3.1 February 20, 2017
0.3.0 February 15, 2017
0.2.0 January 31, 2017
0.1.4 January 27, 2017

Interesting Forks See all

modplug/XamarinMediaManager
Cross platform Xamarin plugin to play Media from PCL
C# - MIT - Last pushed - 1 stars

Something wrong with this page? Make a suggestion

Last synced: 2019-05-19 16:18:46 UTC