ZPFMediaPlayer 1.0.2

dotnet add package ZPFMediaPlayer --version 1.0.2                
NuGet\Install-Package ZPFMediaPlayer -Version 1.0.2                
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="ZPFMediaPlayer" Version="1.0.2" />                
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add ZPFMediaPlayer --version 1.0.2                
#r "nuget: ZPFMediaPlayer, 1.0.2"                
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
// Install ZPFMediaPlayer as a Cake Addin
#addin nuget:?package=ZPFMediaPlayer&version=1.0.2

// Install ZPFMediaPlayer as a Cake Tool
#tool nuget:?package=ZPFMediaPlayer&version=1.0.2                

MediaPlayer for Maui - !!! Preview !!!

Cross platform media player lib for Maui</BR> based on our MediaPlayer for XF (legacy readme.md) and ideas and code of martijn00 ( https://github.com/martijn00/XamarinMediaManager )

.
.
.

The following text is not yet updated ...

You’ll find the story behind this MediaPlayer lib here …

Xmarin.Forms samples for the MediaPlayer …
Simple Xamarin, UWP & WPF samples for the MediaPlayer …
and for those interested some links about the tricks of this library and examples in the wiki section...

Notes and warnings

This is only a preview, so there are missing features. If you are kind and ask for them, perhaps we'll implement them. Otherwise, as is is opensource contribute. PR (pull requests) are wellcome.

Android emulator

12/01/2019 - The mediaplayer control isn't working well in Android emulator, whereas same features work on a physical device.

Current platform support

platform sample build state
UWP XF.UWP Build status 90 % audio
iOS XF.iOS Build status 60 % audio
Android XF.Android Build status 90 % audio
MacOS XF.Mac 60 % audio
WPF XF.WPF 70 % audio

Setup

How to use

A Xamarin.Forms sample showing how to use MediaPlayer is in this Git, but here are the basics ...

authorizations

iOS and MacOS - Info.plist

If you wish to access to streamning sites you should add folowing lines to your Info.plist.

	<key>NSAppTransportSecurity</key>
	<dict>
		<key>NSAllowsArbitraryLoads</key>
		<true/>
		<key> NSAllowsArbitraryLoadsInWebContent</key>
		<true/>
	</dict>

Initialization

Before using the MediaPlayer you should initialize it in the platform dependent project.

Start by adding the using at the header of each concerned file ...

using ZPF.Media;

for an Android project: MainActivity.cs: OnCreate:

...
MediaPlayer.Current.Init();  
LoadApplication(new App());

for a UWP project: App.xaml.cs: OnLaunched:

...
MediaPlayer.Current.Init();  
Xamarin.Forms.Forms.Init(e);
...

for a WPF project: MainWindow.xaml.cs: MainWindow():

...
ZPF.Media.MediaPlayer.Current.Init(this);
Forms.Init();
...
MediaPlayer.Current.Init() UWP iOS Android Mac WPF
Mandatory no no no no yes

Play

MediaPlayer.Current.Play("http://freesound.org/data/previews/273/273629_4068345-lq.mp3");  

On WPF you should try .. catch the Play method for the moment:
[WPF] Fatal exception when playing special song

Native player

platform nativ player
Android Android.Media.MediaPlayer
iOS AVKit.AVPlayerViewController
MacOS AVKit.AVPlayerView
UWP Windows.Media.Playback.MediaPlayer
WPF System.Windows.Controls.MediaElement

Android

Android.Media.MediaPlayer Player = (Android.Media.MediaPlayer)MediaPlayer.Current.Player;  

// Set the low-level power management behavior for the MediaPlayer on Android:
Player.SetWakeMode(Application.Context, Android.OS.WakeLockFlags.Partial);

WakeLockFlags Enum

Remark: The Android Player type will probably change in the future to the ExoPlayer. So check the doc on each release.

UWP

Windows.Media.Playback.MediaPlayer Player = (Windows.Media.Playback.MediaPlayer)MediaPlayer.Current.Player;  

WPF

System.Windows.Controls.MediaElement Player = (System.Windows.Controls.MediaElement)ZPF.Media.MediaPlayer.Current.Player; 

Code Sample

Main page source code from sample program ...

API

Methods

MediaPlayer.Current.Pause();  
MediaPlayer.Current.Play("http://clips.vorwaerts-gmbh.de/big_buck_bunny.mp4");  
MediaPlayer.Current.Play("http://freesound.org/data/previews/273/273629_4068345-lq.mp3");  
MediaPlayer.Current.Play(mi);  
MediaPlayer.Current.Play();  
MediaPlayer.Current.Playlist.Current   
MediaPlayer.Current.Playlist.PlayNext();  
MediaPlayer.Current.Playlist.PlayPrevious();  
MediaPlayer.Current.Playlist.Add( MediaItem.GetNew("http://www.zpf.fr/podcast/02.mp3", MediaType.Audio, MediaLocation.Remote) );   
MediaPlayer.Current.StepBackward(); 
MediaPlayer.Current.StepForward();  
MediaPlayer.Current.Stop();  
MediaPlayer.Current.MediaExtractor.CreateMediaItem(mediaItem);  

Properties

Property Description
Duration TimeSpan
Position TimeSpan
State Playing, Paused, Stopped, Loading, Buffering, Failed
MediaPlayer.Current.Playlist  
MediaPlayer.Current.Playlist.RepeatMode = RepeatMode.Off;  
MediaPlayer.Current.Playlist.ShuffleMode = ShuffleMode.Off;  
MediaPlayer.Current.Play(NextItem);  
MediaPlayer.Current.Play(PreviousItem);  
Volume properties
Property Description
Balance From -1 (Left) to +1 (right). 0 = center.
Volume From 0 to 1.
Muted True or False

Events

event UWP iOS Android Mac WPF
MediaItemChanged X X
MediaItemFailed X X X X
MediaItemFinished X X X X X
PositionChanged X X X X X
StateChanged X X

X = implemented, blank = not yet implemented

Next steps

  • code review
  • iOS, Mac, WPF, ...
  • MediaExtractor (WPF)**
  • sync native playlist with internal playlist (UWP, ...)
  • check ExoPlayer on Android
  • video
  • enhance/(re)design sample application

How to build

EDI

!!! It seam that since update to VS2019 16.1.0/16.1.1 the build doesn't function anymore. It's still fine with VS2017. !!!

On Windows you can build the solution with Visual Studio 2019 with the latest Xamarin, .NET Core and UWP installed.

For the moment the solution doesn't build with VS2019 on MacOS: https://developercommunity.visualstudio.com/content/problem/536913/vsfm-2019-doesnt-work-with-project-file-sdks-like.html .

Nor on Microsoft Visual Studio Professional 2019 Version 16.1.1 https://github.com/onovotny/MSBuildSdkExtras/issues/168 https://developercommunity.visualstudio.com/content/problem/536913/vsfm-2019-doesnt-work-with-project-file-sdks-like.html

Microsoft Visual Studio Professional 2017 Version 15.9.12 OK - Nuget - Android, iOS, MacOS, UWP, WPF

it doesn't build on Microsoft Visual Studio Enterprise 2019 (Preview) for Mac Version 8.1 Preview (8.1 build 2460)

Visual Studio 2017 Developer Command Prompt

It builds on 'Visual Studio 2017 Developer Command Prompt'

Build WPF debug

msbuild zpfmediaplayer.csproj /p:TargetsToBuild=Wpf /t:Rebuild  

Build all platformes debug

msbuild zpfmediaplayer.csproj /p:TargetsToBuild=All /t:Rebuild  

Build WPF release

msbuild zpfmediaplayer.csproj /p:TargetsToBuild=Wpf;Configuration=Release /t:Rebuild  

Build all platformes release (--> Nuget)

msbuild zpfmediaplayer.csproj /p:TargetsToBuild=All;Configuration=Release /t:Rebuild  

Did you like ?

Give me a star or <a href="https://www.buymeacoffee.com/mjVR9nWhC" target="_blank"><img src="https://www.buymeacoffee.com/assets/img/custom_images/purple_img.png" alt="Buy Me A Coffee" style="height: auto !important;width: auto !important;" ></a>

Your coffee keeps me awake while working on projects like this 👍☕

Product Compatible and additional computed target framework versions.
.NET net7.0 is compatible.  net7.0-android was computed.  net7.0-android33.0 is compatible.  net7.0-ios was computed.  net7.0-ios16.1 is compatible.  net7.0-maccatalyst was computed.  net7.0-maccatalyst16.1 is compatible.  net7.0-macos was computed.  net7.0-tvos was computed.  net7.0-windows was computed.  net7.0-windows10.0.19041 is compatible.  net8.0 was computed.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.
  • net7.0

    • No dependencies.
  • net7.0-android33.0

    • No dependencies.
  • net7.0-ios16.1

    • No dependencies.
  • net7.0-maccatalyst16.1

    • No dependencies.
  • net7.0-windows10.0.19041

    • No dependencies.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last updated
1.0.2 309 5/26/2023
1.0.1 308 3/1/2023
0.3.2 1,379 3/25/2020
0.3.1 475 3/20/2020
0.3.0 673 6/10/2019
0.2.2 586 6/2/2019
0.2.0 714 6/2/2019
0.1.0 556 5/26/2019