Exemplo n.º 1
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 {
                Filename = filename
            };
            await StartPlayerAsyncFromAssetsFolder(Application.Context.Assets.OpenFd(filename));

            CurrentFile.Duration = TimeSpan.FromSeconds(this.player.Duration);
            return(CurrentFile);
        }
Exemplo n.º 2
0
        /// <summary>
        /// Sets the media asynchronous.
        /// </summary>
        /// <param name="filename">The filename.</param>
        /// <returns>Task&lt;SoundFile&gt;.</returns>
        public async Task <SoundFile> SetMediaAsync(string filename)
        {
            CurrentFile = new SoundFile {
                Filename = filename
            };

            var file = await ApplicationData.Current.LocalFolder.GetFileAsync(CurrentFile.Filename);

            //TODO: need to clean this events
            GlobalMediaElement.MediaEnded  += GlobalMediaElementMediaEnded;
            GlobalMediaElement.MediaOpened += GlobalMediaElementMediaOpened;

            GlobalMediaElement.Source = new Uri(CurrentFile.Filename, UriKind.Relative);

            return(CurrentFile);
        }
 /// <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 {
             Filename = filename
         };
         var url = NSUrl.FromFilename(CurrentFile.Filename);
         this.player = AVAudioPlayer.FromUrl(url);
         this.player.FinishedPlaying += (object sender, AVStatusEventArgs e) =>
         {
             if (e.Status)
             {
                 OnFileFinished(new SoundFinishedEventArgs(CurrentFile));
             }
         };
         CurrentFile.Duration = TimeSpan.FromSeconds(this.player.Duration);
         return CurrentFile;
     }));
 }
Exemplo n.º 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)
        {
            this.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 this.tcsSetMedia.Task;
            }));
        }
Exemplo n.º 5
0
        /// <summary>
        /// Sets the media asynchronous.
        /// </summary>
        /// <param name="filename">The filename.</param>
        /// <returns>Task&lt;SoundFile&gt;.</returns>
        public async Task<SoundFile> SetMediaAsync(string filename)
        {
            CurrentFile = new SoundFile {Filename = filename};

	        var file = await ApplicationData.Current.LocalFolder.GetFileAsync(CurrentFile.Filename);

            //TODO: need to clean this events
            GlobalMediaElement.MediaEnded += GlobalMediaElementMediaEnded;
            GlobalMediaElement.MediaOpened += GlobalMediaElementMediaOpened;

            GlobalMediaElement.Source = new Uri(CurrentFile.Filename, UriKind.Relative);

            return CurrentFile;
        }
Exemplo n.º 6
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 {Filename = filename};
     await StartPlayerAsyncFromAssetsFolder(Application.Context.Assets.OpenFd(filename));
     CurrentFile.Duration = TimeSpan.FromSeconds(this.player.Duration);
     return CurrentFile;
 }
Exemplo n.º 7
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 {Filename = filename};
                 var url = NSUrl.FromFilename(CurrentFile.Filename);
                 this.player = AVAudioPlayer.FromUrl(url);
                 this.player.FinishedPlaying += (object sender, AVStatusEventArgs e) =>
                     {
                         if (e.Status)
                         {
                             OnFileFinished(new SoundFinishedEventArgs(CurrentFile));
                         }
                     };
                 CurrentFile.Duration = TimeSpan.FromSeconds(this.player.Duration);
                 return CurrentFile;
             });
 }
		/// <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>
 /// Initializes a new instance of the <see cref="SoundFinishedEventArgs"/> class.
 /// </summary>
 /// <param name="f">The f.</param>
 public SoundFinishedEventArgs(SoundFile f)
 {
     File = f;
 }
Exemplo n.º 10
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)
        {
            this.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 this.tcsSetMedia.Task;
            });
        }