using AVFoundation;
using Foundation;
using System;
using TranslateMobile.iOS;
using Xamarin.Forms;
using static TranslateMobile.MainPage;

[assembly: Dependency(typeof(TextToSpeechImplementation))]

namespace TranslateMobile.iOS
{
	public class TextToSpeechImplementation : ITextToSpeech
	{
		public TextToSpeechImplementation() { }
		public Action OnFinishedPlaying { get; set; }

		public void Lire(string strURL)
		{
			//Utilisation du AVAudioPlayer Apple pour restitution du streaming
			AVAudioPlayer player = AVAudioPlayer.FromUrl(NSUrl.FromString(strURL));
			player.Play();
			player.FinishedPlaying += Player_FinishedPlaying;
		}

		private void Player_FinishedPlaying(object sender, AVStatusEventArgs e)
		{
			OnFinishedPlaying?.Invoke();
		}
	}

}