/// <summary> /// Initializes a new instance of the <see cref="SoundFinishedEventArgs"/> class. /// </summary> /// <param name="f">The f.</param> public SoundFinishedEventArgs(SoundFile f) { File = f; }
/// <summary> /// set media as an asynchronous operation. /// </summary> /// <param name="filename">The filename.</param> /// <returns>Task<SoundFile>.</returns> public async Task<SoundFile> SetMediaAsync(string filename) { CurrentFile = new SoundFile(); CurrentFile.Filename = filename; await StartPlayerAsyncFromAssetsFolder(Application.Context.Assets.OpenFd(filename)); CurrentFile.Duration = TimeSpan.FromSeconds(_player.Duration); return CurrentFile; }
/// <summary> /// Sets the media asynchronous. /// </summary> /// <param name="filename">The filename.</param> /// <returns>Task<SoundFile>.</returns> public Task<SoundFile> SetMediaAsync(string filename) { _tcsSetMedia = new TaskCompletionSource<SoundFile>(); CurrentFile = new SoundFile {Filename = filename}; return Task.Run(() => { if (Application.GetResourceStream(new Uri(CurrentFile.Filename, UriKind.Relative)) == null) { MessageBox.Show("File doesn't exist!"); } //TODO: need to clean this events GlobalMediaElement.MediaEnded += GlobalMediaElementMediaEnded; GlobalMediaElement.MediaOpened += GlobalMediaElementMediaOpened; GlobalMediaElement.Source = new Uri(CurrentFile.Filename, UriKind.Relative); return _tcsSetMedia.Task; }); }
/// <summary> /// Sets the media asynchronous. /// </summary> /// <param name="filename">The filename.</param> /// <returns>Task<SoundFile>.</returns> public Task<SoundFile> SetMediaAsync(string filename) { return Task.Run( () => { CurrentFile = new SoundFile(); CurrentFile.Filename = filename; var url = NSUrl.FromFilename(CurrentFile.Filename); _player = AVAudioPlayer.FromUrl(url); _player.FinishedPlaying += (object sender, AVStatusEventArgs e) => { if (e.Status) { OnFileFinished(new SoundFinishedEventArgs(CurrentFile)); } }; CurrentFile.Duration = TimeSpan.FromSeconds(_player.Duration); return CurrentFile; }); }