{"id":13693067,"url":"https://github.com/Baseflow/XamarinMediaManager","last_synced_at":"2025-05-02T21:31:15.583Z","repository":{"id":35037215,"uuid":"39155970","full_name":"Baseflow/XamarinMediaManager","owner":"Baseflow","description":"Cross platform Xamarin plugin to play and control Audio and Video","archived":false,"fork":false,"pushed_at":"2024-07-03T14:22:02.000Z","size":20658,"stargazers_count":769,"open_issues_count":145,"forks_count":306,"subscribers_count":51,"default_branch":"develop","last_synced_at":"2024-11-06T14:46:35.137Z","etag":null,"topics":["audio","baseflow","exoplayer","media","mediamanager","mediaplayer","netstandard","nuget","player","video","xamarin","xamarin-forms"],"latest_commit_sha":null,"homepage":"https://baseflow.com","language":"C#","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/Baseflow.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":"CONTRIBUTING.md","funding":".github/FUNDING.yml","license":"LICENSE","code_of_conduct":"CODE_OF_CONDUCT.md","threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null},"funding":{"github":"Baseflow","custom":"https://baseflow.com/contact"}},"created_at":"2015-07-15T19:10:17.000Z","updated_at":"2024-10-30T01:46:25.000Z","dependencies_parsed_at":"2024-09-23T02:00:36.407Z","dependency_job_id":"66d9ef9d-a9ee-40d4-9406-415d02ab774e","html_url":"https://github.com/Baseflow/XamarinMediaManager","commit_stats":{"total_commits":1126,"total_committers":60,"mean_commits":"18.766666666666666","dds":0.5088809946714032,"last_synced_commit":"de3cc728b6bd50600f802a120b9bf24724294f5d"},"previous_names":["martijn00/xamarinmediamanager"],"tags_count":45,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Baseflow%2FXamarinMediaManager","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Baseflow%2FXamarinMediaManager/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Baseflow%2FXamarinMediaManager/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Baseflow%2FXamarinMediaManager/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Baseflow","download_url":"https://codeload.github.com/Baseflow/XamarinMediaManager/tar.gz/refs/heads/develop","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":223581917,"owners_count":17168655,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["audio","baseflow","exoplayer","media","mediamanager","mediaplayer","netstandard","nuget","player","video","xamarin","xamarin-forms"],"created_at":"2024-08-02T17:01:05.110Z","updated_at":"2024-11-12T19:30:23.328Z","avatar_url":"https://github.com/Baseflow.png","language":"C#","funding_links":["https://github.com/sponsors/Baseflow","https://baseflow.com/contact"],"categories":["Media"],"sub_categories":[],"readme":"# MediaManager - Cross platform media plugin for Xamarin and Windows\n* Designed to be simple and easy to use\n* Native playback of media files from remote http(s), embedded and local sources\n* Native media notifications and remote controls\n* Queue and playback management by default\n* Playback status (Playing, Buffering, Loading, Paused, Progress)\n* Events for media handling to hook into\n\n## Status: \n[![Build status](https://ci.appveyor.com/api/projects/status/be78iac0bl7q930i?svg=true)](https://ci.appveyor.com/project/martijn00/xamarinmediamanager)\n![GitHub tag](https://img.shields.io/github/tag/martijn00/XamarinMediaManager.svg)\n[![NuGet](https://img.shields.io/nuget/v/Plugin.MediaManager.svg?label=NuGet)](https://www.nuget.org/packages/Plugin.MediaManager/)\n[![MyGet](https://img.shields.io/myget/martijn00/v/Plugin.MediaManager.svg)](https://www.myget.org/F/martijn00/api/v3/index.json)\n\n# Support\n\n* Feel free to open an issue. Make sure to use one of the templates!\n* Commercial support is available. Integration with your app or services, samples, feature request, etc. Email: [hello@baseflow.com](mailto:hello@baseflow.com)\n* Powered by: [baseflow.com](https://baseflow.com)\n\n# Wiki\n\nMore documenatation and information is available on the [Wiki](https://github.com/martijn00/XamarinMediaManager/wiki)\n\n# Blogs\n\n* [Xamarin Blog](https://devblogs.microsoft.com/xamarin/play-audio-and-video-with-the-mediamanager-plugin-for-xamarin/)\n* [Baseflow Blog](https://baseflow.com/blogs/mobile-video-matters/)\n\n## Installation\n\nAdd the [NuGet package](https://www.nuget.org/packages/Plugin.MediaManager/) to all the projects you want to use it in.\n\n* In Visual Studio - Tools \u003e NuGet Package Manager \u003e Manage Packages for Solution\n* Select the Browse tab, search for MediaManager\n* Select Plugin.MediaManager\n* Install into each project within your solution\n\n**Platform Support**\n\n|Platform|Supported|Version|Player|\n| ------------------- | :-----------: | :------------------: |:------------------: |\n|.Net Standard|Yes|2.0+|MediaManager|\n|Xamarin.Forms|Yes|3.2+|MediaManager|\n|Xamarin.Android|Yes|API 16+|ExoPlayer|\n|Xamarin.iOS|Yes|iOS 10+|AVPlayer|\n|Xamarin.Mac|Yes|3.0+|AVPlayer|\n|Xamarin.tvOS|Yes|10.0+|AVPlayer|\n|Tizen|Yes|4.0+|MediaPlayer|\n|Windows 10 UWP|Yes|10+|MediaPlayer|\n|Windows WPF (.NET Framework)|Yes|4.7.2+|MediaPlayer|\n|Windows WPF (.NET Core)|Yes|3.1+|MediaPlayer|\n\n## Usage\n\nCall **MediaManager.Current** from any .Net library or Xamarin project to gain access to APIs.\n\n### **IMPORTANT:** Initialize plugin\n\nMake sure to call Init() in all the native platforms on startup of your app.\n\n```csharp\nCrossMediaManager.Current.Init();\n```\n\nOptionally 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.\n\n```csharp\npublic class MainActivity : AppCompatActivity\n{\n\tprotected override void OnCreate(Bundle savedInstanceState)\n\t{\n\t\tbase.OnCreate(savedInstanceState);\n\t\tSetContentView(Resource.Layout.main_activity);\n\n\t\tCrossMediaManager.Current.Init(this);\n\t}\n}\n```\n\nWhen 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`.\nThat should bring your app back into focus when tapped. [You can read more about it here](https://developer.android.com/guide/topics/manifest/activity-element.html#lmode)\n\n```csharp\n[Activity(LaunchMode = LaunchMode.SingleTop)]\npublic class MainActivity : AppCompatActivity\n```\n\nIf you want to handle when the app is opened via a notification tap, you can override `OnNewIntent` on your activity:\n\n```csharp\nprotected override void OnNewIntent(Intent intent)\n{\n    base.OnNewIntent(intent);\n    // TODO: Handle app opened from notification tap.\n}\n```\n\n### Disposing\n\nThe player can be disposed via `CrossMediaManager.Current.Dispose()`. Make sure to call `CrossMediaManager.Current.Init()` if you used dispose before playing another media file.\n\n### Play a single media item\n\n```csharp\n//Audio\nawait CrossMediaManager.Current.Play(\"https://ia800806.us.archive.org/15/items/Mp3Playlist_555/AaronNeville-CrazyLove.mp3\");\n//Video\nawait CrossMediaManager.Current.Play(\"http://clips.vorwaerts-gmbh.de/big_buck_bunny.mp4\");\n```\n\n### Play multiple media items\n\n```csharp\npublic IList\u003cstring\u003e Mp3UrlList =\u003e new[]{\n\t\"https://ia800806.us.archive.org/15/items/Mp3Playlist_555/AaronNeville-CrazyLove.mp3\",\n\t\"https://ia800605.us.archive.org/32/items/Mp3Playlist_555/CelineDion-IfICould.mp3\",\n\t\"https://ia800605.us.archive.org/32/items/Mp3Playlist_555/Daughtry-Homeacoustic.mp3\",\n\t\"https://storage.googleapis.com/uamp/The_Kyoto_Connection_-_Wake_Up/01_-_Intro_-_The_Way_Of_Waking_Up_feat_Alan_Watts.mp3\",\n\t\"https://aphid.fireside.fm/d/1437767933/02d84890-e58d-43eb-ab4c-26bcc8524289/d9b38b7f-5ede-4ca7-a5d6-a18d5605aba1.mp3\"\n\t};\n\nawait CrossMediaManager.Current.Play(Mp3UrlList);\n```\n\n### Other play possibilities\n\n```csharp\nTask\u003cIMediaItem\u003e Play(IMediaItem mediaItem);\nTask\u003cIMediaItem\u003e Play(string uri);\nTask\u003cIMediaItem\u003e Play(IEnumerable\u003cIMediaItem\u003e items);\nTask\u003cIMediaItem\u003e Play(IEnumerable\u003cstring\u003e items);\nTask\u003cIMediaItem\u003e Play(FileInfo file);\nTask\u003cIMediaItem\u003e Play(DirectoryInfo directoryInfo);\nTask\u003cIMediaItem\u003e PlayFromAssembly(string resourceName, Assembly assembly = null);\nTask\u003cIMediaItem\u003e PlayFromResource(string resourceName);\n```\n\n* Playing from a `File` can be done for example by using the `File` and `Directory` api's. You download a file from the internet and save it somewhere using these .NET api's.\n* When playing from `Assembly` you need to add a media file to a assembly and set the build action to `Embedded resource`.\n* When playing from a `Resource` you should add your media file for example to the `Assets` or `raw` folder on Android, and the `Resources` folder on iOS.\n\nFor example:\n\n```csharp\nawait CrossMediaManager.Current.PlayFromAssembly(\"somefile.mp3\", typeof(BaseViewModel).Assembly);\nawait CrossMediaManager.Current.PlayFromResource(\"assets:///somefile.mp3\");\nawait CrossMediaManager.Android.PlayFromResource(Resource.Raw.somefile.ToString());\n```\n\n### Control the player \n\n```csharp\nawait CrossMediaManager.Current.Play();\nawait CrossMediaManager.Current.Pause();\nawait CrossMediaManager.Current.PlayPause();\nawait CrossMediaManager.Current.Stop();\n\nawait CrossMediaManager.Current.StepForward();\nawait CrossMediaManager.Current.StepBackward();\n\nawait CrossMediaManager.Current.SeekToStart();\nawait CrossMediaManager.Current.SeekTo(TimeSpan position);\n```\n\n### Control the Queue\n\n```csharp\nawait CrossMediaManager.Current.PlayPrevious();\nawait CrossMediaManager.Current.PlayNext();\nawait CrossMediaManager.Current.PlayPreviousOrSeekToStart();\nawait CrossMediaManager.Current.PlayQueueItem(IMediaItem mediaItem);\nawait CrossMediaManager.Current.PlayQueueItem(int index);\n```\n\nExtensions:\n\n```csharp\nvoid ToggleRepeat();\nvoid ToggleShuffle();\n```\n\n### Retrieve and set information\n\n```csharp\nIDictionary\u003cstring, string\u003e RequestHeaders { get; set; }\nTimeSpan StepSizeForward { get; set; }\nTimeSpan StepSizeBackward { get; set; }\nMediaPlayerState State { get; }\nTimeSpan Position { get; }\nTimeSpan Duration { get; }\nTimeSpan Buffered { get; }\nfloat Speed { get; set; }\nRepeatMode RepeatMode { get; set; }\nShuffleMode ShuffleMode { get; set; }\nbool ClearQueueOnPlay { get; set; }\nbool AutoPlay { get; set; }\nbool KeepScreenOn { get; set; }\n```\n\nExtensions:\n\n```csharp\nbool IsPlaying();\nbool IsBuffering();\nbool IsPrepared();\nbool IsStopped();\n```\n\nProperties available on CrossMediaManager.Current.MediaPlayer.*\n\n```csharp\nIVideoView VideoView { get; set; }\nbool AutoAttachVideoView { get; set; }\nVideoAspectMode VideoAspect { get; set; }\nbool ShowPlaybackControls { get; set; }\nint VideoHeight { get; }\nint VideoWidth { get; }\n```\n\n### Hook into events\n\n```csharp\nevent StateChangedEventHandler StateChanged;\nevent BufferedChangedEventHandler BufferedChanged;\nevent PositionChangedEventHandler PositionChanged;\nevent MediaItemFinishedEventHandler MediaItemFinished;\nevent MediaItemChangedEventHandler MediaItemChanged;\nevent MediaItemFailedEventHandler MediaItemFailed;\n```\n\n### Retrieve metadata for media\n\nDepending on the platform and the media item metadata will be extracted from ID3 data in the file.\n\n```csharp\nCrossMediaManager.Current.Queue.Current.Title;\nCrossMediaManager.Current.Queue.Current.AlbumArt;\nCrossMediaManager.Current.Queue.Current.*\n```\n\nSince the metadata might not be available immediately you can subscribe for updates like this:\n\n```csharp\nvar mediaItem = await CrossMediaManager.Current.Play(\"https://ia800806.us.archive.org/15/items/Mp3Playlist_555/AaronNeville-CrazyLove.mp3\");\nmediaItem.MetadataUpdated += (sender, args) =\u003e {\n\tvar title = args.MediaItem.Title;\n};\n```\n\nAlternatively you could also use the `PropertyChanged` event to see updates to the metadata.\n\nYou can also get a single frame from a video:\n\n```csharp\nstring url = \"https://something.com/something.mov\";\nvar mediaItem = await CrossMediaManager.Current.Extractor.CreateMediaItem(url);\nvar image = await CrossMediaManager.Current.Extractor.GetVideoFrame(mediaItem, TimeSpan.FromSeconds(1));\nImageSource imageSource = image.ToImageSource();\nFormsImage.Source = imageSource;\n```\n\n### Add Video Player to the UI\n\n**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:**\n\n```csharp\nCrossMediaManager.Current.MediaPlayer.AutoAttachVideoView = false;\n```\n\n**After that you can manually add the video view like this:**\n\nFor android we need a `VideoView` in the axml layout.\n```xml\n\u003cmediamanager.platforms.android.video.VideoView\n\tandroid:id=\"@+id/your_videoview\"\n\tandroid:layout_width=\"match_parent\"\n\tandroid:layout_height=\"300dp\" /\u003e\n```\n\nThen find the view in code:\n```csharp\nplayerView = view.FindViewById\u003cVideoView\u003e(Resource.Id.your_videoview);\n```\n\nFor iOS, MacOS or tvOS we need to add a `VideoView` either in code, or in a Xib or Storyboard.\n```csharp\nvar playerView = new VideoView();\nView.AddSubview(playerView);\n```\n\nThen for all platforms we have to add the player view to the `MediaPlayer`\n```csharp\nCrossMediaManager.Current.MediaPlayer.VideoView = playerView;\n```\n\n### Play a non standard format like HLS, Dash or SS\n\nMediaManager 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:\n\n```csharp\nvar item = await CrossMediaManager.Current.Extractor.CreateMediaItem(\"https://devstreaming-cdn.apple.com/videos/streaming/examples/bipbop_16x9/bipbop_16x9_variant.m3u8\");\nitem.MediaType = MediaType.Hls;\n\nawait CrossMediaManager.Current.Play(item);\n```\n\nBy enforcing it there is still no guarantee that the native system actually is able to play the item. \n\n## Platform specific features\n\n|Feature|Android|iOS, Mac, tvOS|UWP|Tizen|WPF\n| ------------------- | :-----------: | :------------------: | :------------------: |:------------------: |:------------------: |\n|Audio|✓|✓|✓|✓|✓|\n|Video|✓|✓|✓|✓|✓|\n|Queue|✓|✓|✓|✓|✓|\n|Notifications|✓|✓|✓|✓|✓|\n|Volume|✓|✓|✓|✓|✓|\n|Media Extraction|✓|✓|✓|✓|✓|\n|HLS|✓|✓|||\n|DASH|✓||||\n|SmoothStreaming|✓||||\n|ChromeCast|✓||||\n|Airplay||✓|||\n|Xamarin.Forms|✓|✓|✓||✓|\n\nYou can also directly access the native platform implementation if you need it!\n```csharp\n//Android\nCrossMediaManager.Android.*\n//iOS, MacOS or tvOS\nCrossMediaManager.Apple.*\n//UWP\nCrossMediaManager.Windows.*\n//Tizen\nCrossMediaManager.Tizen.*\n//WPF\nCrossMediaManager.Wpf.*\n```\n\n## Xamarin.Forms\n\nAdding a `VideoView` to a Page in Forms is easy as this:\n\n```xml\n\u003cmm:VideoView VerticalOptions=\"FillAndExpand\" Source=\"http://clips.vorwaerts-gmbh.de/big_buck_bunny.mp4\" /\u003e\n```\n\nYour Xamarin.Forms page could look like this:\n\n```xml\n\u003c?xml version=\"1.0\" encoding=\"utf-8\" ?\u003e\n\u003cContentPage\n    xmlns=\"http://xamarin.com/schemas/2014/forms\"\n    xmlns:x=\"http://schemas.microsoft.com/winfx/2009/xaml\"\n    xmlns:mm=\"clr-namespace:MediaManager.Forms;assembly=MediaManager.Forms\"\n    x:Class=\"YourClassName\" \u003e\n    \u003cContentPage.Content\u003e\n        \u003cStackLayout\u003e\n            \u003cmm:VideoView VerticalOptions=\"FillAndExpand\" Source=\"http://clips.vorwaerts-gmbh.de/big_buck_bunny.mp4\" ShowControls=\"False\" /\u003e\n        \u003c/StackLayout\u003e\n    \u003c/ContentPage.Content\u003e\n\u003c/ContentPage\u003e\n```\n\nYou 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.\n\nIf you want a Page that contains a player you can open the `VideoPage`.\n\n```csharp\nNavigation.PushAsync(new MediaManager.Forms.VideoPage());\n```\n\n## Reactive extensions\n\nAdd the [Reactive NuGet package](https://www.nuget.org/packages/Plugin.MediaManager.Reactive/) to all the projects you want to use it in.\n\nUsage:\n\n```csharp\nCrossMediaManager.Current.Reactive().*\n```\n\n## FFmpegMediaMetadataRetriever on Android\n\nIf you want to use FFmpegMediaMetadataRetriever on Android to extract the metadata you can set to use this extension like this:\n\n```csharp\nCrossMediaManager.Android.Extractor = new FFmpegMediaExtractor();\n```\n\n## Intercept share requests from the native platform or other apps\n\n**Android:**\n```csharp\n//Add code to the OnCreate(Bundle savedInstanceState) of your MainActivity\nif(await CrossMediaManager.Android.PlayFromIntent(Intent))\n{\n    //If true maybe do an action like opening a Player Page.\n}\n```\n\n## **IMPORTANT**\n**Android:**\n\n* This library will automatically request the following permissions: `AccessWifiState`, `AccessNetworkState`, `Internet`, `ForegroundService` and `WakeLock`. You do not need to add them to your AndroidManifest.\n* Your app must target Android SDK v28 or higher\n* This library uses ExoPlayer for video playback. This requires that you enable the following\n* Dex tool to D8: `\u003cAndroidDexTool\u003ed8\u003c/AndroidDexTool\u003e`\n* Optional enable R8 Linker to make code smaller: `\u003cAndroidLinkTool\u003er8\u003c/AndroidLinkTool\u003e`\n* Aapt2 build tools: `\u003cAndroidUseAapt2\u003etrue\u003c/AndroidUseAapt2\u003e`\n* Disable multi-dex when using D8 and R8 with AAPT2. Your code should be small enough with those.\n\n**iOS:**\n\n* 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\n\n```xml\n\u003ckey\u003eUIBackgroundModes\u003c/key\u003e\n\u003carray\u003e\n\t\u003cstring\u003eaudio\u003c/string\u003e\n\t\u003cstring\u003efetch\u003c/string\u003e\n\u003c/array\u003e\n```\n\n* If you are playing audio from a http resource you have to take care of [ATS](https://developer.xamarin.com/guides/ios/platform_features/introduction_to_ios9/ats/). Optionally you can disable this for playing media. Add the following to your info.plist:\n\n```xml\n\u003ckey\u003eNSAppTransportSecurity\u003c/key\u003e\n\u003cdict\u003e\n\t\u003ckey\u003eNSAllowsArbitraryLoadsInMedia\u003c/key\u003e\n\t\u003ctrue/\u003e\n\u003c/dict\u003e\n```\n\nIf you want to disable more you could add: `NSAllowsLocalNetworking` or even `NSAllowsArbitraryLoads` to disable all checks.\n\n* 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).\n\n**UWP:**\n\n* In the Package.appxmanifest under capabilities you need to select: \"Background Media Playback\", \"Internet\"\n* Optionally add \"Music Library\" and \"Videos Library\" as well if you use that\n\n**Tizen:**\n\n* You must request `http://tizen.org/privilege/internet`, `http://tizen.org/privilege/mediastorage`, and `http://tizen.org/privilege/externalstorage` privileges\n\n## Building the source code\n\n* On Windows you need Visual Studio 2019 with the latest Xamarin, .NET Core, UWP and Windows 10 SDK installed.\n* 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` to make a release build run: `msbuild MediaManager.sln /t:rebuild /p:Configuration=Release`. To restore your nuget packages run: `msbuild MediaManager.sln /t:restore`.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FBaseflow%2FXamarinMediaManager","html_url":"https://awesome.ecosyste.ms/projects/github.com%2FBaseflow%2FXamarinMediaManager","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FBaseflow%2FXamarinMediaManager/lists"}