Skip to content

ZeProgFactory/MediaPlayer

Folders and files

NameName
Last commit message
Last commit date

Latest commit

ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 

Repository files navigation

MediaPlayer for Maui - !!! Preview !!!

Cross platform media player lib for Maui
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 novotnyllc/MSBuildSdkExtras#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 Buy Me A Coffee

Your coffee keeps me awake while working on projects like this ๐Ÿ‘โ˜•