Skip to content

Commit 0602e09

Browse files
committed
Added support for mp3 file playback on linux. Suppressed linux console output.
1 parent c43243f commit 0602e09

4 files changed

Lines changed: 18 additions & 11 deletions

File tree

NetCoreAudio/Players/LinuxPlayer.cs

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,19 @@
11
using NetCoreAudio.Interfaces;
2+
using System.IO;
23

34
namespace NetCoreAudio.Players
45
{
56
internal class LinuxPlayer : UnixPlayerBase, IPlayer
67
{
7-
protected override string BashToolName
8+
protected override string GetBashCommand(string fileName)
89
{
9-
get
10+
if (".mp3".Equals(Path.GetExtension(fileName)))
1011
{
11-
return "aplay";
12+
return "mpg123 -q";
13+
}
14+
else
15+
{
16+
return "aplay -q";
1217
}
1318
}
1419
}

NetCoreAudio/Players/MacPlayer.cs

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,9 @@ namespace NetCoreAudio.Players
44
{
55
internal class MacPlayer : UnixPlayerBase, IPlayer
66
{
7-
protected override string BashToolName
7+
protected override string GetBashCommand(string fileName)
88
{
9-
get
10-
{
11-
return "afplay";
12-
}
9+
return "afplay";
1310
}
1411
}
1512
}

NetCoreAudio/Players/UnixPlayerBase.cs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,24 +5,25 @@
55

66
namespace NetCoreAudio.Players
77
{
8-
internal class UnixPlayerBase : IPlayer
8+
internal abstract class UnixPlayerBase : IPlayer
99
{
1010
private Process _process = null;
1111

1212
internal const string PauseProcessCommand = "kill -STOP {0}";
1313
internal const string ResumeProcessCommand = "kill -CONT {0}";
1414

15-
protected virtual string BashToolName { get; }
16-
1715
public event EventHandler PlaybackFinished;
1816

1917
public bool Playing { get; private set; }
2018

2119
public bool Paused { get; private set; }
2220

21+
protected abstract string GetBashCommand(string fileName);
22+
2323
public async Task Play(string fileName)
2424
{
2525
await Stop();
26+
var BashToolName = GetBashCommand(fileName);
2627
_process = StartBashProcess($"{BashToolName} '{fileName}'");
2728
_process.EnableRaisingEvents = true;
2829
_process.Exited += HandlePlaybackFinished;

README.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,10 @@ The library allows playback of audio files on .NET Core on any operating system
66

77
The library exposes Player class, which detects the OS the library is running on and abstracts away any OS-specific audio playback implementations.
88

9+
### MP3 Playback on linux
10+
11+
The library relies on the mpg123 audio player for playback of .mp3 files on linux.
12+
913
## Properties
1014

1115
### bool Playing

0 commit comments

Comments
 (0)