示例#1
0
 /// <summary>
 /// Initializes a new instance of the <see cref="SoundFinishedEventArgs"/> class.
 /// </summary>
 /// <param name="f">The f.</param>
 public SoundFinishedEventArgs(SoundFile f)
 {
     File = f;
 }
示例#2
0
		/// <summary>
		/// set media as an asynchronous operation.
		/// </summary>
		/// <param name="filename">The filename.</param>
		/// <returns>Task&lt;SoundFile&gt;.</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;
		}
示例#3
0
		/// <summary>
		/// Sets the media asynchronous.
		/// </summary>
		/// <param name="filename">The filename.</param>
		/// <returns>Task&lt;SoundFile&gt;.</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;
			});
		}
示例#4
0
 /// <summary>
 /// Sets the media asynchronous.
 /// </summary>
 /// <param name="filename">The filename.</param>
 /// <returns>Task&lt;SoundFile&gt;.</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;
             });
 }
示例#5
0
 /// <summary>
 /// Initializes a new instance of the <see cref="SoundFinishedEventArgs"/> class.
 /// </summary>
 /// <param name="f">The f.</param>
 public SoundFinishedEventArgs(SoundFile f)
 {
     File = f;
 }