Created
February 19, 2019 09:10
-
-
Save ufukhawk/0cb023790c7b673ef40dec195ae45c34 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class AudioPlayerService : IAudioPlayerService | |
{ | |
private AVAudioPlayer _audioPlayer = null; | |
public Action OnFinishedPlaying { get; set; } | |
public AudioPlayerService() | |
{ | |
} | |
public void Play(string pathToAudioFile) | |
{ | |
if (_audioPlayer != null) | |
{ | |
_audioPlayer.FinishedPlaying -= Player_FinishedPlaying; | |
_audioPlayer.Stop(); | |
} | |
string localUrl = pathToAudioFile; | |
_audioPlayer = AVAudioPlayer.FromUrl(NSUrl.FromFilename(localUrl)); | |
_audioPlayer.FinishedPlaying += Player_FinishedPlaying; | |
_audioPlayer.Play(); | |
} | |
private void Player_FinishedPlaying(object sender, AVStatusEventArgs e) | |
{ | |
OnFinishedPlaying?.Invoke(); | |
} | |
public void Pause() | |
{ | |
_audioPlayer?.Pause(); | |
} | |
public void Play() | |
{ | |
_audioPlayer?.Play(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment