Ejemplo n.º 1
0
		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;
		}
Ejemplo n.º 2
0
		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;
			});
		}
Ejemplo n.º 3
0
 public SoundFinishedEventArgs(SoundFile f)
 {
     File = f;
 }
Ejemplo n.º 4
0
        /// <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;
		}