File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 11using NetCoreAudio . Interfaces ;
2+ using System . IO ;
23
34namespace 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 }
Original file line number Diff line number Diff 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}
Original file line number Diff line number Diff line change 55
66namespace 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 ;
Original file line number Diff line number Diff line change @@ -6,6 +6,10 @@ The library allows playback of audio files on .NET Core on any operating system
66
77The 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
You can’t perform that action at this time.
0 commit comments