Class MediaPlayer
A Reusable Channel which can Load files like a Player.
MediaPlayer is perfect for UIs, as it implements
Also, unlike normal, Properties/Effects set on a MediaPlayer persist through subsequent loads.
What is MediaPlayer?
A MediaPlayer associates properties to itself instead of a Channel (as done by BASS).
This allows usage like a typical Music Player where you Load a Music, Play it, Load Another, Play it, and so on... while the properties or effects you set on it persist.
You load different music files using the <xref:ManagedBass.MediaPlayer.Load(System.String)> method. Every Property/Effect/DSP you set on a MediaPlayer persists beyond subsequent loads.
They are appropriate for Binding to the UI due to implementation of INotifyPropertyChanged interface.
MediaPlayerFX adds features from BassFx: Tempo, Pitch and Reverse.
Using MediaPlayer on UWP (NOT VERIFIED)
UWP requires that files be loaded asynchronously.
You should use a type inherited from MediaPlayer.
using Windows.Storage;
namespace ManagedBass
{
public class MediaPlayerUWP : MediaPlayer
{
public async void LoadAsync(string FileName)
{
//Get the file we want to play.
StorageFile fileToPlay = await StorageFile.GetFileFromPathAsync(FileName);
// Request permission to access file.
AccessCache.StorageApplicationPermissions.FutureAccessList.Add(fileToPlay);
// Load file asynchronously.
await Task.Run(() => Load(FileName));
}
}
}
Namespace: System.Dynamic.ExpandoObject
Assembly: ManagedBass.dll
Syntax
public class MediaPlayer : INotifyPropertyChanged, IDisposable
Constructors
MediaPlayer()
Properties
Album
Artist
Balance
Gets or Sets Balance (Panning) (-1 ... 0 ... 1). -1 Represents Completely Left. 1 Represents Completely Right. Default is 0.
Declaration
public double Balance { get; set; }
Property Value
Double
|
Device
Gets or Sets the Playback Device used.
Declaration
public int Device { get; set; }
Property Value
Int32
|
Duration
Gets the Playback Duration.
Declaration
public TimeSpan Duration { get; }
Property Value
TimeSpan
|
Frequency
Gets or Sets the Playback Frequency in Hertz. Default is 44100 Hz.
Declaration
public double Frequency { get; set; }
Property Value
Double
|
Handle
Channel Handle of the loaded audio file.
Declaration
protected int Handle { get; }
Property Value
Int32
|
Loop
Gets or Sets whether the Playback is looped.
Declaration
public bool Loop { get; set; }
Property Value
Boolean
|
Position
Gets or Sets the Playback Position.
Declaration
public TimeSpan Position { get; set; }
Property Value
TimeSpan
|
State
Gets the Playback State of the Channel.
Declaration
public PlaybackState State { get; }
Property Value
PlaybackState
|
Title
Volume
Gets or Sets the Playback Volume.
Declaration
public double Volume { get; set; }
Property Value
Double
|
Methods
Dispose()
Frees all resources used by the player.
Declaration
public virtual void Dispose()
InitProperties()
Initializes Properties on every call to LoadAsync(String).
Declaration
protected virtual void InitProperties()
LoadAsync(String)
Loads a file into the player.
Declaration
public Task<bool> LoadAsync(string FileName)
Parameters
String
FileName
Path to the file to Load. |
Returns
Task<Boolean>
true on succes, false on failure. |
OnLoad(String)
Override this method for custom loading procedure.
Declaration
protected virtual int OnLoad(string FileName)
Parameters
String
FileName
Path to the File to Load. |
Returns
Int32
true on Success, false on failure |
OnPropertyChanged(String)
Fires the PropertyChanged event.
Declaration
protected virtual void OnPropertyChanged(string PropertyName = null)
Parameters
String
PropertyName
|
Pause()
Play()
Stop()
Stops the Channel Playback.
Declaration
public bool Stop()
Returns
Boolean
|
Remarks
Difference from ChannelStop(Int32): Playback is restarted when Play() is called.
Events
Disposed
Fired when this Channel is Disposed.
Declaration
public event EventHandler Disposed
Event Type
EventHandler
|
MediaEnded
Fired when the Media Playback Ends
Declaration
public event EventHandler MediaEnded
Event Type
EventHandler
|
MediaFailed
Fired when the Playback fails
Declaration
public event EventHandler MediaFailed
Event Type
EventHandler
|
MediaLoaded
Fired when a Media is Loaded.
Declaration
public event Action<int> MediaLoaded
Event Type
Action<Int32>
|
PropertyChanged
Fired when a property value changes.
Declaration
public event PropertyChangedEventHandler PropertyChanged
Event Type
PropertyChangedEventHandler
|