Skip to content

Commit e3b9455

Browse files
committed
- Added basic streaming support.
- Renamed "Playlists" and "Media" to "Artists" and "Tracks".
1 parent ee1e70a commit e3b9455

File tree

3 files changed

+37
-6
lines changed

3 files changed

+37
-6
lines changed

src/model/IPlayer.cs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,5 +39,11 @@ public interface IPlayer
3939
/// Method to decrease audio playback volume.
4040
/// </summary>
4141
void DecreaseVolume();
42+
43+
/// <summary>
44+
/// Method to play an audio stream from a URL.
45+
/// </summary>
46+
/// <param name="streamURL">The stream URL of the audio file to play.</param>
47+
void PlayStream(string streamURL);
4248
}
4349
}

src/model/WinPlayer.cs

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,11 @@ public void Pause()
5757
/// <param name="args">The StoppedEventArgs.</param>
5858
public void OnPlaybackStopped(object sender, StoppedEventArgs args)
5959
{
60-
this.audioFileReader.Dispose();
60+
if (this.audioFileReader != null)
61+
{
62+
this.audioFileReader.Dispose();
63+
}
64+
6165
this.outputDevice.Dispose();
6266
}
6367

@@ -92,5 +96,24 @@ public void DecreaseVolume()
9296

9397
this.outputDevice.Volume -= 0.1f;
9498
}
99+
100+
/// <inheritdoc/>
101+
public void PlayStream(string streamURL)
102+
{
103+
try
104+
{
105+
using (var mf = new MediaFoundationReader(streamURL))
106+
{
107+
this.outputDevice.Init(mf);
108+
this.outputDevice.Play();
109+
}
110+
}
111+
catch (System.ArgumentException)
112+
{
113+
}
114+
catch (System.IO.FileNotFoundException)
115+
{
116+
}
117+
}
95118
}
96119
}

src/view/Gui.cs

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ public void Start()
120120
playbackControls.Add(playBtn, pauseBtn, stopBtn, increaseVolumeButton, decreaseVolumeButton);
121121

122122
// Create the left-hand playlists view.
123-
leftPane = new FrameView("Playlists")
123+
leftPane = new FrameView("Artists")
124124
{
125125
X = 0,
126126
Y = 1, // for menu
@@ -130,7 +130,7 @@ public void Start()
130130
};
131131

132132
categories = new List<string>();
133-
categories.Add("Rockin' Tunes");
133+
categories.Add("Zhund");
134134
categoryListView = new ListView(categories)
135135
{
136136
X = 0,
@@ -148,7 +148,7 @@ public void Start()
148148

149149
leftPane.Add(categoryListView);
150150

151-
rightPane = new FrameView("Media")
151+
rightPane = new FrameView("Tracks")
152152
{
153153
X = 25,
154154
Y = 1, // for menu
@@ -215,8 +215,7 @@ private void OpenStream()
215215
{
216216
var d = new Dialog("Open Stream", 50, 15);
217217

218-
// Type text here: ______
219-
var editLabel = new Label("Enter the url of the audio stream to load\n(MP3 only):")
218+
var editLabel = new Label("Enter the url of the audio stream to load:\n(.mp3 only)")
220219
{
221220
X = 0,
222221
Y = 0,
@@ -230,9 +229,12 @@ private void OpenStream()
230229
Width = 42,
231230
};
232231

232+
// d.KeyPress += (a) => streamURL.Text = a.KeyEvent.ToString();
233+
233234
var loadStream = new Button(12, 7, "Load Stream");
234235
loadStream.Clicked += () =>
235236
{
237+
this.player.PlayStream(streamURL.Text.ToString());
236238
Application.RequestStop();
237239
};
238240

0 commit comments

Comments
 (0)