Skip to content

Commit

Permalink
Disable silencePlayer on catalyst
Browse files Browse the repository at this point in the history
(might be needed again later but I mostly just need to commit a code example for catalyst detection...)
  • Loading branch information
Difegue committed Apr 17, 2024
1 parent bc0481b commit f7051f4
Showing 1 changed file with 8 additions and 5 deletions.
13 changes: 8 additions & 5 deletions Sources/Stylophone.iOS/Services/NowPlayingService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ public class NowPlayingService
private MPDConnectionService _mpdService;
private IApplicationStorageService _storageService;

private AVAudioPlayer _silencePlayer;
private AVAudioPlayer? _silencePlayer;

public NowPlayingService(MPDConnectionService mpdService, IApplicationStorageService storageService)
{
Expand All @@ -30,6 +30,9 @@ public NowPlayingService(MPDConnectionService mpdService, IApplicationStorageSer

// https://stackoverflow.com/questions/48289037/using-mpnowplayinginfocenter-without-actually-playing-audio
// TODO This breaks when LibVLC playback stops
if (new NSProcessInfo().IsMacCatalystApplication)
return;

_silencePlayer = new AVAudioPlayer(new NSUrl("silence.wav",false,NSBundle.MainBundle.ResourceUrl), null, out var error);
_silencePlayer.NumberOfLoops = -1;
}
Expand Down Expand Up @@ -111,19 +114,19 @@ private void UpdateState(MpdStatus status)
switch (status.State)
{
case MpdState.Play:
_silencePlayer.Play();
_silencePlayer?.Play();
_nowPlayingInfo.PlaybackRate = 1;
break;
case MpdState.Pause:
_silencePlayer.Stop();
_silencePlayer?.Stop();
_nowPlayingInfo.PlaybackRate = 0;
break;
case MpdState.Stop:
_silencePlayer.Stop();
_silencePlayer?.Stop();
_nowPlayingInfo.PlaybackRate = 0;
break;
case MpdState.Unknown:
_silencePlayer.Stop();
_silencePlayer?.Stop();
_nowPlayingInfo.PlaybackRate = 0;
break;
default:
Expand Down

0 comments on commit f7051f4

Please sign in to comment.