public async System.Threading.Tasks.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; }
public Task<SoundFile> SetMediaAsync (string filename) { return Task.Run<SoundFile> (() => { _currentFile = new SoundFile (); _currentFile.Filename = filename; NSUrl url = NSUrl.FromFilename (_currentFile.Filename); player = AVAudioPlayer.FromUrl (url); player.FinishedPlaying += (object sender, AVStatusEventArgs e) => { if (e.Status) { this.OnFileFinished (new SoundFinishedEventArgs (this._currentFile)); } }; _currentFile.Duration = TimeSpan.FromSeconds (player.Duration); return _currentFile; }); }
public SoundFinishedEventArgs(SoundFile f) { File = f; }
/// <summary> /// Sets the media asynchronous. /// </summary> /// <param name="filename">The filename.</param> /// <returns></returns> public Task<SoundFile> SetMediaAsync(string filename) { tcsSetMedia = new TaskCompletionSource<SoundFile>(); _currentFile = new SoundFile(); _currentFile.Filename = filename; Device.BeginInvokeOnMainThread(() => { if (Application.GetResourceStream(new Uri(_currentFile.Filename, UriKind.Relative)) == null) MessageBox.Show("File doesn't exist!"); //TODO: need to clean this events GlobalMediaElement.MediaEnded += GlobalMediaElement_MediaEnded; GlobalMediaElement.MediaOpened += GlobalMediaElement_MediaOpened; GlobalMediaElement.Source = new Uri(_currentFile.Filename, UriKind.Relative); }); return tcsSetMedia.Task; }
public SoundFinishedEventArgs (SoundFile f) { File = f; }