See commit description for changes
Added PageContainer to dynamically load pages within the main content. Added player component to control music playback(Half functional). Added playback changed event not the player service.
This commit is contained in:
@ -3,12 +3,12 @@ using System.IO;
|
||||
|
||||
namespace Aurora.Backend.Models
|
||||
{
|
||||
public abstract class BaseSong
|
||||
public abstract class BaseMedia
|
||||
{
|
||||
private bool _loaded;
|
||||
private Stream _stream;
|
||||
|
||||
public BaseSong()
|
||||
public BaseMedia()
|
||||
{
|
||||
_loaded = false;
|
||||
Id = Guid.NewGuid().ToString();
|
@ -3,9 +3,9 @@ using System.IO;
|
||||
|
||||
namespace Aurora.Backend.Models
|
||||
{
|
||||
public class LocalSong : BaseSong
|
||||
public class LocalAudio : BaseMedia
|
||||
{
|
||||
public LocalSong(FileInfo fileInfo)
|
||||
public LocalAudio(FileInfo fileInfo)
|
||||
{
|
||||
File = fileInfo;
|
||||
}
|
||||
@ -15,6 +15,9 @@ namespace Aurora.Backend.Models
|
||||
|
||||
#endregion Properties
|
||||
|
||||
/// <summary>
|
||||
/// Override load method.
|
||||
/// </summary>
|
||||
public override void Load()
|
||||
{
|
||||
if (this.DataStream != null)
|
||||
@ -26,6 +29,9 @@ namespace Aurora.Backend.Models
|
||||
base.Load();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Override unload method
|
||||
/// </summary>
|
||||
public override void Unload()
|
||||
{
|
||||
if (this.DataStream != null)
|
@ -12,14 +12,14 @@ namespace Aurora.Backend.Services
|
||||
#region Fields
|
||||
private string _pathName = "/Users/brandonwatson/Music/iTunes/iTunes Media/Music";
|
||||
private string _extensions = ".wav,.mp3,.aiff,.flac,.m4a,.m4b,.wma";
|
||||
private Dictionary<string, BaseSong> _library;
|
||||
private Dictionary<string, BaseMedia> _library;
|
||||
|
||||
|
||||
#endregion Fields
|
||||
|
||||
public LibraryService()
|
||||
{
|
||||
_library = new Dictionary<string, BaseSong>();
|
||||
_library = new Dictionary<string, BaseMedia>();
|
||||
LoadLibrary();
|
||||
}
|
||||
|
||||
@ -27,10 +27,10 @@ namespace Aurora.Backend.Services
|
||||
/// Gets the songs.
|
||||
/// </summary>
|
||||
/// <returns>The songs.</returns>
|
||||
public ObservableCollection<BaseSong> GetLibrary()
|
||||
public ObservableCollection<BaseMedia> GetLibrary()
|
||||
{
|
||||
ObservableCollection<BaseSong> collection = new ObservableCollection<BaseSong>();
|
||||
foreach (KeyValuePair<string, BaseSong> pair in _library)
|
||||
ObservableCollection<BaseMedia> collection = new ObservableCollection<BaseMedia>();
|
||||
foreach (KeyValuePair<string, BaseMedia> pair in _library)
|
||||
{
|
||||
collection.Add(pair.Value);
|
||||
}
|
||||
@ -50,7 +50,7 @@ namespace Aurora.Backend.Services
|
||||
{
|
||||
TagLib.File tagFile = TagLib.File.Create(file.FullName);
|
||||
|
||||
BaseSong song = new LocalSong(file)
|
||||
BaseMedia song = new LocalAudio(file)
|
||||
{
|
||||
Title = tagFile.Tag.Title,
|
||||
Album = tagFile.Tag.Album,
|
||||
|
@ -1,33 +0,0 @@
|
||||
using System;
|
||||
using Aurora.Backend.Models;
|
||||
using LibVLCSharp.Shared;
|
||||
|
||||
namespace Aurora.Backend.Services
|
||||
{
|
||||
public class PlayerService : BaseService<PlayerService>
|
||||
{
|
||||
public PlayerService()
|
||||
{
|
||||
}
|
||||
|
||||
public void Play(BaseSong song)
|
||||
{
|
||||
using (var libVLC = new LibVLC())
|
||||
{
|
||||
song.Load();
|
||||
var media = new Media(libVLC, song.DataStream);
|
||||
using (var mp = new MediaPlayer(media))
|
||||
{
|
||||
media.Dispose();
|
||||
mp.Play();
|
||||
Console.ReadKey();
|
||||
}
|
||||
|
||||
song.Unload();
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
}
|
9
Aurora/Backend/Services/PlayerService/PlaybackState.cs
Normal file
9
Aurora/Backend/Services/PlayerService/PlaybackState.cs
Normal file
@ -0,0 +1,9 @@
|
||||
using System;
|
||||
|
||||
public enum PlaybackState
|
||||
{
|
||||
Playing,
|
||||
Stopped,
|
||||
Buffering,
|
||||
|
||||
}
|
@ -0,0 +1,18 @@
|
||||
using System;
|
||||
|
||||
namespace Aurora.Backend.Services.PlayerService
|
||||
{
|
||||
public delegate void PlaybackStateChangedEventHandler(object source, PlaybackStateChangedEventArgs e);
|
||||
|
||||
public class PlaybackStateChangedEventArgs : EventArgs
|
||||
{
|
||||
public PlaybackState OldState { get; }
|
||||
public PlaybackState NewState { get; }
|
||||
|
||||
public PlaybackStateChangedEventArgs(PlaybackState oldState, PlaybackState newState)
|
||||
{
|
||||
OldState = oldState;
|
||||
NewState = newState;
|
||||
}
|
||||
}
|
||||
}
|
116
Aurora/Backend/Services/PlayerService/PlayerService.cs
Normal file
116
Aurora/Backend/Services/PlayerService/PlayerService.cs
Normal file
@ -0,0 +1,116 @@
|
||||
using System;
|
||||
using Aurora.Backend.Models;
|
||||
using LibVLCSharp.Shared;
|
||||
|
||||
namespace Aurora.Backend.Services.PlayerService
|
||||
{
|
||||
public class PlayerService : BaseService<PlayerService>
|
||||
{
|
||||
private BaseMedia _currentMedia;
|
||||
private MediaPlayer _mediaPlayer;
|
||||
private LibVLC _libvlc;
|
||||
private PlaybackState _state;
|
||||
|
||||
public PlayerService()
|
||||
{
|
||||
_libvlc = new LibVLC();
|
||||
_state = PlaybackState.Stopped;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Event handler for changing playback states.
|
||||
/// </summary>
|
||||
public event PlaybackStateChangedEventHandler PlaybackStateChanged;
|
||||
|
||||
/// <summary>
|
||||
/// The state of playback
|
||||
/// </summary>
|
||||
/// <value></value>
|
||||
public PlaybackState PlaybackState
|
||||
{
|
||||
get { return _state; }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Load media into the media player.
|
||||
/// </summary>
|
||||
/// <param name="media">Media to load</param>
|
||||
public void LoadMedia(BaseMedia media)
|
||||
{
|
||||
if (_state == PlaybackState.Playing || _state == PlaybackState.Buffering)
|
||||
{
|
||||
Unload();
|
||||
}
|
||||
_currentMedia = media;
|
||||
_currentMedia.Load();
|
||||
var md = new Media(_libvlc, _currentMedia.DataStream);
|
||||
_mediaPlayer = new MediaPlayer(md);
|
||||
_mediaPlayer.Stopped += OnStopped;
|
||||
md.Dispose();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Play currently loaded media.
|
||||
/// </summary>
|
||||
public void Play()
|
||||
{
|
||||
PlaybackStateChanged.Invoke(this, new PlaybackStateChangedEventArgs(_state, PlaybackState.Playing));
|
||||
_state = PlaybackState.Playing;
|
||||
_mediaPlayer.Play();
|
||||
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Pause currently loaded media.
|
||||
/// </summary>
|
||||
public void Pause()
|
||||
{
|
||||
PlaybackStateChanged.Invoke(this, new PlaybackStateChangedEventArgs(_state, PlaybackState.Buffering));
|
||||
_state = PlaybackState.Buffering;
|
||||
_mediaPlayer.Pause();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Stop currently loaded media.
|
||||
/// </summary>
|
||||
public void Stop()
|
||||
{
|
||||
PlaybackStateChanged.Invoke(this, new PlaybackStateChangedEventArgs(_state, PlaybackState.Stopped));
|
||||
_state = PlaybackState.Stopped;
|
||||
_mediaPlayer.Stop();
|
||||
}
|
||||
|
||||
public void Enqueue(BaseMedia song)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
public void Dequeue(BaseMedia song)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Unload currently loaded media.
|
||||
/// </summary>
|
||||
private void Unload()
|
||||
{
|
||||
_currentMedia.Unload();
|
||||
_mediaPlayer.Media = null;
|
||||
_mediaPlayer = null;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Event fired when currently loaded media player stops.
|
||||
/// </summary>
|
||||
/// <param name="sender"></param>
|
||||
/// <param name="args"></param>
|
||||
private void OnStopped(object sender, EventArgs args)
|
||||
{
|
||||
PlaybackStateChanged.Invoke(this, new PlaybackStateChangedEventArgs(_state, PlaybackState.Stopped));
|
||||
_state = PlaybackState.Stopped;
|
||||
this.Unload();
|
||||
}
|
||||
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user