Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,4 +24,4 @@ A list of open tasks can be found on our [issues page](https://github.com/markja

## Screenshot

<img src="https://user-images.githubusercontent.com/20845425/98192579-493ed580-1ee9-11eb-9188-fe6e6e1c0c55.png" alt="Screenshot of MusicSharp">
<img src="https://user-images.githubusercontent.com/20845425/98765417-1e062b80-23ac-11eb-9cb7-4046d8e979e9.png" alt="Screenshot of MusicSharp">
2 changes: 1 addition & 1 deletion src/MusicSharp.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,12 @@

<ItemGroup>
<PackageReference Include="NAudio" Version="1.10.0" />
<PackageReference Include="PlaylistsNET" Version="1.1.2" />
<PackageReference Include="StyleCop.Analyzers" Version="1.1.118">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="Terminal.Gui" Version="0.90.3" />
<PackageReference Include="z440.atl.core" Version="3.13.0" />
</ItemGroup>

<ItemGroup>
Expand Down
6 changes: 6 additions & 0 deletions src/model/IPlayer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -45,5 +45,11 @@ public interface IPlayer
/// Method to decrease audio playback volume.
/// </summary>
void DecreaseVolume();

/// <summary>
/// Play an audio file contained in a playlist.
/// </summary>
/// <param name="path">The path to the audio file.</param>
void PlayFromPlaylist(string path);
}
}
18 changes: 10 additions & 8 deletions src/model/PlaylistLoader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,10 @@ namespace MusicSharp
{
using System.Collections.Generic;
using System.IO;

using System.Text;
using PlaylistsNET.Content;
using PlaylistsNET.Models;
using ATL;
using ATL.Playlist;

/// <summary>
/// The PlaylistLoader class loads a playlist of a given type.
Expand All @@ -24,15 +25,16 @@ public class PlaylistLoader
/// <param name="userPlaylist">The user specified playlist path.</param>
public List<string> LoadPlaylist(string userPlaylist)
{
var parser = PlaylistParserFactory.GetPlaylistParser(".m3u");
IPlaylistIO theReader = PlaylistIOFactory.GetInstance().GetPlaylistIO(userPlaylist);

// convert string to stream
byte[] byteArray = Encoding.UTF8.GetBytes(userPlaylist);
MemoryStream stream = new MemoryStream(byteArray);
List<string> filePaths = new List<string>();

IBasePlaylist playlist = parser.GetFromStream(stream);
foreach (string s in theReader.FilePaths)
{
filePaths.Add(s);
}

return playlist.GetTracksPaths();
return filePaths;
}
}
}
19 changes: 19 additions & 0 deletions src/model/WinPlayer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,25 @@ public void PlayPause()
}
}

public void PlayFromPlaylist(string path)
{
if (this.outputDevice != null)
{
this.outputDevice.Dispose();

try
{
this.audioFileReader = new AudioFileReader(path);
this.outputDevice.Init(this.audioFileReader);
this.outputDevice.Play();
}
catch (System.IO.FileNotFoundException)
{
}
}

}

/// <summary>
/// Dispose of our device once playback is stopped.
/// </summary>
Expand Down
62 changes: 22 additions & 40 deletions src/view/Tui.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,11 @@ namespace MusicSharp
/// </summary>
public class Tui
{
private static List<string> categories;
private static ListView categoryListView;
private static FrameView leftPane;
private static FrameView rightPane;
private static List<string> playlistTracks;
private static ListView playlistView;
private static FrameView playlistPane;
private static FrameView playbackControls;
private static FrameView nowPlaying;
private static ListView scenarioListView;
private static StatusBar statusBar;

/// <summary>
Expand Down Expand Up @@ -65,12 +63,9 @@ public void Start()

new MenuItem("Open S_tream", "Open a music stream", () => this.OpenStream()),

new MenuItem("_Quit", "Exit MusicSharp", () => Application.RequestStop()),
}),
new MenuItem("Open Pla_ylist", "Load a playlist", () => this.LoadPlaylist()),

new MenuBarItem("_Playlists", new MenuItem[]
{
new MenuItem("Open Pla_ylist", string.Empty, () => this.LoadPlaylist()),
new MenuItem("_Quit", "Exit MusicSharp", () => Application.RequestStop()),
}),

new MenuBarItem("_Help", new MenuItem[]
Expand Down Expand Up @@ -128,18 +123,19 @@ public void Start()
playbackControls.Add(playPauseButton, stopButton, increaseVolumeButton, decreaseVolumeButton);

// Create the left-hand playlists view.
leftPane = new FrameView("Artists")
playlistPane = new FrameView("Tracks")
{
X = 0,
Y = 1, // for menu
Width = 25,
Width = Dim.Fill(),
Height = 23,
CanFocus = false,
};

categories = new List<string>();
categories.Add("Zhund");
categoryListView = new ListView(categories)
// The list of tracks in the playlist.
playlistTracks = new List<string>();

playlistView = new ListView(playlistTracks)
{
X = 0,
Y = 0,
Expand All @@ -149,32 +145,14 @@ public void Start()
CanFocus = true,
};

categoryListView.OpenSelectedItem += (a) =>
// Play the selection when a playlist path is clicked.
playlistView.OpenSelectedItem += (a) =>
{
rightPane.SetFocus();
};

leftPane.Add(categoryListView);

rightPane = new FrameView("Tracks")
{
X = 25,
Y = 1, // for menu
Width = Dim.Fill(),

Height = 23,
CanFocus = true,
this.player.LastFileOpened = a.Value.ToString();
this.player.PlayFromPlaylist(this.player.LastFileOpened);
};

scenarioListView = new ListView()
{
X = 0,
Y = 0,
Width = Dim.Fill(),
Height = 23,
AllowsMarking = false,
CanFocus = true,
};
playlistPane.Add(playlistView);

// Create the audio progress bar frame.
nowPlaying = new FrameView("Now Playing")
Expand All @@ -199,7 +177,7 @@ public void Start()
nowPlaying.Add(this.AudioProgressBar);

// Add the layout elements and run the app.
top.Add(menu, leftPane, rightPane, playbackControls, nowPlaying, statusBar);
top.Add(menu, playlistPane, playbackControls, nowPlaying, statusBar);

Application.Run();
}
Expand Down Expand Up @@ -234,6 +212,7 @@ private void OpenFile()
}
}

// Open and play an audio stream.
private void OpenStream()
{
var d = new Dialog("Open Stream", 50, 15);
Expand Down Expand Up @@ -271,6 +250,7 @@ private void OpenStream()
Application.Run(d);
}

// Load a playlist file. Currently, only M3U is supported.
private void LoadPlaylist()
{
var d = new OpenDialog("Open", "Open a playlist") { AllowsMultipleSelection = false };
Expand All @@ -291,8 +271,10 @@ private void LoadPlaylist()
{
foreach (string track in this.playlist)
{
MessageBox.Query(track, "Close");
playlistTracks.Add(track);
}

Application.Run();
}
}
}
Expand Down