예제 #1
0
 public void PrevPlayTrack()
 {
     _mediaPlayer?.Stop();
     currentTrackIndex = trackModels.IndexOf(currentTrack) - 1;
     if (currentTrackIndex < 0)
     {
         currentTrackIndex = trackModels.Count - 1;
     }
     currentTrack = trackModels[currentTrackIndex];
     StartPlayTrack(currentTrack);
 }
예제 #2
0
 public void StopAudio()
 {
     try
     {
         _isExecute = true;
         _AudioPlayer?.Stop();
     }
     catch (Exception ex)
     {
         LogTracking.LogTrace(ex.ToString());
     }
 }
예제 #3
0
 public override void Play(string filename)
 {
     try
     {
         /// todo: Устранить загадочную ошибку
         var Soundurl = NSUrl.FromFilename(filename);
         if (player != null)
             player.Stop();
         player = AVAudioPlayer.FromUrl(Soundurl);
         player.Stop();
         player.CurrentTime = player.Duration * 2;
         player.NumberOfLoops = 1;
         player.Volume = 1.0f;
         player.FinishedPlaying += DidFinishPlaying;
         player.PrepareToPlay();
         player.Play();
     }
     catch (Exception e)
     {
         Console.WriteLine("PlaySound: Error: " + e.Message, true);
     }
 }
예제 #4
0
        public async Task <bool> PlaySound(string filename)
        {
            // Music enabled?
            if (!EffectsOn)
            {
                return(false);
            }

            ////--------BEGIN: way to play multiple sounds simultaneously, but in the Pinyin app we need them to be linear-----
            //// Initialize sound
            //var effect = await NewSound(filename, EffectsVolume);
            //_soundEffects.Add(effect);
            //
            //_soundPlaying = effect;
            ////--------END way to play multiple sounds simultaneously, but in the Pinyin app we need them to be linear-----

            var     songUrl = new NSUrl(Path.Combine(SoundPath, filename));
            NSError err;
            var     fileType = filename.Split('.').Last();

            if (_soundPlaying != null)
            {
                if (_soundPlaying.Playing)
                {
                    _soundPlaying.Stop();
                    _soundPlaying.CurrentTime = 0.0f;
                }

                _soundPlaying.Dispose();
            }

            _soundPlaying = new AVAudioPlayer(songUrl, fileType, out err);
            _soundPlaying.Play();

            return(true);
        }
예제 #5
0
 public void StopMedia()
 {
     soundEffect.Stop();
 }
예제 #6
0
        void Initialize()
        {
            BubbleImageView = new UIImageView {
                TranslatesAutoresizingMaskIntoConstraints = false
            };
            MessageLabel = new UILabel {
                TranslatesAutoresizingMaskIntoConstraints = false,
                Lines = 0,
                PreferredMaxLayoutWidth = 220f
            };
            AudioPlayButton = new UIButton
            {
                TranslatesAutoresizingMaskIntoConstraints = false,
                Hidden = true
            };
            ImageAttachment = new UIButton
            {
                TranslatesAutoresizingMaskIntoConstraints = false,
                Hidden = true,
            };

            //ImageAttachment = UIButton.FromType(UIButtonType.Custom);
            //ImageAttachment.Frame.Width  = new RectangleF(100, 100, 60, 50);
            ImageAttachment.TouchUpInside += delegate
            {
                string documentsPath = Environment.GetFolderPath(Environment.SpecialFolder.Personal);
                //sAudioFileName = msg.AudioFileName;
                string localPath = Path.Combine(documentsPath, msg.ImgFileName);
                if (File.Exists(localPath) == true)
                {
                    ChatOn.objMyChat().ChatImageNotification(msg.ImgFileName);

                    //NSObject sender = new NSObject();
                    //ViewController_Test controller = .Storyboard.InstantiateViewController("ViewController_Test") as ViewController_Test;
                    //UINavigationController nav =new UINavigationController();
                    //nav.PushViewController(ViewControlle, true);

                    //ViewController_Test controller = objChat.Storyboard.InstantiateViewController("ViewController_Test") as ViewController_Test;
                    //objChat.NavigationController.PushViewController(controller, true);


                    //var storyboard = UIStoryboard.FromName("Main", null);
                    //ViewController_Test controller = storyboard.InstantiateViewController("ViewController_Test") as ViewController_Test;
                    //UINavigationController nav = new UINavigationController();
                    //nav.PushViewController(controller, true);

                    //nav.PerformSegue("ShowImage", sender);
                    //	ImageAttachment.SetBackgroundImage(UIImage.FromFile("Attach1.png"), UIControlState.Normal);
                    //}
                    //else
                    //{
                    //	LoadDownloadImageFile(msg.ImgFileName);
                }
            };


            AudioPlayButton.TouchUpInside += delegate
            {
                string documentsPath = Environment.GetFolderPath(Environment.SpecialFolder.Personal);
                //sAudioFileName = msg.AudioFileName;
                string localPath = Path.Combine(documentsPath, msg.AudioFileName);
                if (File.Exists(localPath) == true)
                {
                    try
                    {
                        if (player == null)
                        {
                            AudioPlayButton.SetBackgroundImage(UIImage.FromFile("Final Image/StopSmall.png"), UIControlState.Normal);
                            LoadAudioPlay(localPath);
                        }
                        else
                        {
                            if (player.Playing == true)
                            {
                                AudioPlayButton.SetBackgroundImage(UIImage.FromFile("Final Image/PlaySmall.png"), UIControlState.Normal);
                                player.Stop();
                                player = null;
                            }
                        }
                    }
                    catch (Exception ex)
                    {
                        Console.Out.WriteLine(ex.StackTrace);
                    }
                }
                else
                {
                    LoadDownloadAudioFile(msg.AudioFileName);
                }
                //AudioStopButton.Hidden = false;
                //new UIAlertView("Touch1", "TouchUpInside handled", null, "OK", null).Show();
            };


            //AudioStopButton.TouchUpInside += delegate
            //{
            //	//new UIAlertView("Touch1", "TouchUpInside handled", null, "OK", null).Show();
            //	AudioStopButton.Hidden = true;
            //};
            //AudioDownloadButton.TouchUpInside += delegate
            //{
            //	new UIAlertView("Download", "TouchUpInside handled", null, "OK", null).Show();
            //};

            //AudioPlayButton = new UIButton
            //{
            //	TranslatesAutoresizingMaskIntoConstraints = false,
            //	Frame = new CoreGraphics.CGRect(160, 30, 30, 30),


            //};


            AudioPlayButton.SetBackgroundImage(UIImage.FromFile("Final Image/PlaySmall.png"), UIControlState.Normal);
            //AudioStopButton.SetBackgroundImage(UIImage.FromFile("Final Image/StopSmall.png"), UIControlState.Normal);
            //AudioDownloadButton.SetBackgroundImage(UIImage.FromFile("Final Image/DownloadSmall.png"), UIControlState.Normal);

            ContentView.AddSubviews(BubbleImageView, MessageLabel, AudioPlayButton, ImageAttachment);           //,AudioStopButton,AudioDownloadButton
        }
예제 #7
0
 public void Stop()
 {
     player?.Stop();
 }
예제 #8
0
 public void StopPlayBack()
 {
     _player.Stop();
 }
 partial void BtnStop_TouchUpInside(UIButton sender)
 {
     //Backgroundmusic stop
     player.Stop();
 }
예제 #10
0
 private void internalStop()
 {
     _player.Stop();
 }
예제 #11
0
 public void StopAudio()
 {
     player?.Stop();
     player = null;
 }
예제 #12
0
 private void stopIos()
 {
     _player.Stop();
 }
예제 #13
0
 public void Stop()
 {
     _audioPlayer?.Stop();
 }
예제 #14
0
using AVFoundation;
using ClubManagement.IBLL;
using Foundation;
using Radar.iOS;
using System;
using System.Collections.Generic;

using Xamarin.Forms;
using ClubManagement.Model;
using AudioToolbox;
using System.Threading.Tasks;
using CoreMedia;
using UIKit;

[assembly: Dependency(typeof(AudioiOS))]

namespace Radar.iOS
{
    public class AudioiOS : IAudio
    {
        float _volume = 15;
        AudioCanalEnum _canal = AudioCanalEnum.Nenhum;
        IList<string> _audioAtual = new List<string>();
        int _audioIndex = 0;
        AVAudioPlayer _player;

        public AudioCanalEnum Canal
        {
            get {
                return _canal;
            }

            set
            {
                _canal = value;
            }
        }

        public float Volume {
            get {
                return _volume;
            }
            set {
                _volume = value;
            }
        }

		 AVAudioPlayer criarAudio(string arquivo)
		{
			//UIApplicationState sharedApplication = new UIApplicationState();
			NSUrl songURL = new NSUrl(arquivo);
			NSError err;

			var state = UIApplication.SharedApplication.ApplicationState;
			if (state.ToString() != "Background")
			{
				AVAudioPlayer player = new AVAudioPlayer(songURL, "wav", out err);
				player.Volume = Volume;
				player.NumberOfLoops = 0;
				return player;
			}
			else {

				NSUrl url = NSUrl.FromFilename(arquivo);
				//SystemSound notificationSound = SystemSound.FromFile(NotificationSoundPath);
				SystemSound mySound = new SystemSound(url);

				mySound.AddSystemSoundCompletion(SystemSound.Vibrate.PlaySystemSound);
				var asset = AVAsset.FromUrl(NSUrl.FromFilename(arquivo));

				CMTime audioDuration = asset.Duration;
				double tempo = audioDuration.Value / audioDuration.TimeScale;

				mySound.PlaySystemSound();
				esperaFinalizarSom(tempo);
			}

			return null;
		}

		public void esperaFinalizarSom(double tempo)
		{
			int tempoInt = Convert.ToInt32(tempo);
			if (tempoInt > 5 )
			{
				tempoInt = Convert.ToInt32(tempo) * 1000 + 1000;
			}
			else {
				tempoInt = Convert.ToInt32(tempo) * 1000 + 1000;
			}

			Task.Delay(tempoInt).Wait();
		}

		  void playProximo()
		{
			if (_audioAtual != null && _audioIndex < _audioAtual.Count)
			{
				string arquivo = _audioAtual[_audioIndex];
				_audioIndex++;
				_player = criarAudio(arquivo);
				var state = UIApplication.SharedApplication.ApplicationState;
				if (state.ToString() != "Background")
				{
					_player.FinishedPlaying += (sender, e) =>
					{
						playProximo();

					} ;
					_player.Play();
				}
				else {
					playProximo();
				}


			}
			else {
				//_player.Dispose();
				_player = null;
			}
		}

		public void play(string[] arquivos)
        {
            _audioIndex = 0;
            _audioAtual = null;
           if (_player != null)
            {
                if (_player.Playing)
                    _player.Stop();
                _player.Dispose();
               _player = null;
            }
            _audioIndex = 0;
			if(arquivos != null)
            _audioAtual = arquivos;
            playProximo();
        }

        public void play(string arquivo)
        {
			var player = criarAudio(arquivo);
			//criarAudio(arquivo);
			var state = UIApplication.SharedApplication.ApplicationState;
			if (state.ToString() != "Background")
			{
				player.Play();
			}
        }
    }
}


예제 #15
0
 private void Player_FinishedPlaying(object sender, AVStatusEventArgs e)
 {
     Player.Stop();
     Player.Dispose();
     mStatus = PlayStatus.Completed;
 }
예제 #16
0
 public void StopPlaying()
 {
     _player?.Stop();
 }
 public void StopSound()
 {
     backgroundmusic.Stop();
     backgroundmusic.Dispose();
 }
 ///<Summary>
 /// Stop playack and set the current position to the beginning
 ///</Summary>
 public void Stop()
 {
     player?.Stop();
     Seek(0);
 }
예제 #19
0
		public static async Task<bool> LikePost(Post post, UIButton likeButton, UITableView tableView = null, NSIndexPath indexPath = null)
		{
			if (post.liked || post.IsExpired())
			{
				return false;
			}

			likeButton.SetImage(UIImage.FromBundle("LikeSelected"), UIControlState.Normal);
			likeButton.SetImage(UIImage.FromBundle("LikeSelected"), UIControlState.Highlighted);
			likeButton.SetImage(UIImage.FromBundle("LikeSelected"), UIControlState.Selected);
			UIView.Animate(.3, delegate
			{
				likeButton.Transform = CoreGraphics.CGAffineTransform.MakeScale((nfloat)1.7, (nfloat)1.7);
			}, delegate
			{
				likeButton.Transform = CoreGraphics.CGAffineTransform.MakeScale((nfloat)1, (nfloat)1);
			});



			if (post.userPoster.idUser != Globe.SharedInstance.User.idUser)
			{
				post.liked = true;
				post.expiration = post.expiration + 60000;
				likeButton.SetImage(UIImage.FromBundle("LikeSelected"), UIControlState.Normal);
				likeButton.SetImage(UIImage.FromBundle("LikeSelected"), UIControlState.Highlighted);
				likeButton.SetImage(UIImage.FromBundle("LikeSelected"), UIControlState.Selected);


				AVAudioSession audioSession = AVAudioSession.SharedInstance();
				NSError error = audioSession.SetCategory(AVAudioSessionCategory.Ambient, AVAudioSessionCategoryOptions.MixWithOthers);
				audioSession.SetActive(true, out error);


				AVAudioPlayer player = new AVAudioPlayer(new NSUrl("ticksound.m4a"), "m4a", out error);
				player.NumberOfLoops = 1;
				player.Play();
				player.FinishedPlaying += (sender, e) =>
				{
					player.Stop();
					player = null;
				};

				try
				{
					bool result = await TenServices.LikePost(post);
					if (!result)
					{
						post.liked = false;
						likeButton.SetImage(UIImage.FromBundle("Like"), UIControlState.Normal);
						likeButton.SetImage(UIImage.FromBundle("Like"), UIControlState.Highlighted);
						likeButton.SetImage(UIImage.FromBundle("Like"), UIControlState.Selected);
					}
					else {
						if (tableView != null && indexPath != null)
						{
							tableView.ReloadRows(new NSIndexPath[] { indexPath }, UITableViewRowAnimation.None);
						}
					}
					return result;
				}
				catch (RESTError)
				{
					post.liked = false;
					likeButton.SetImage(UIImage.FromBundle("Like"), UIControlState.Normal);
					likeButton.SetImage(UIImage.FromBundle("Like"), UIControlState.Highlighted);
					likeButton.SetImage(UIImage.FromBundle("Like"), UIControlState.Selected);
				}
				finally
				{
					if (!post.liked)
					{
						post.expiration = post.expiration - 60000;
					}
				}
			}

			return false;
		}
		void playAudio ()
		{
			Debug.WriteLine ("Playing converted audio...");
			
			UpdateFormatInfo (fileInfo, destinationURL);
			startButton.SetTitle ("Playing Output File...", UIControlState.Disabled);

			// set category back to something that will allow us to play audio since kAudioSessionCategory_AudioProcessing will not
			AudioSession.Category = AudioSessionCategory.MediaPlayback;

			// play the result
			NSError error;
			player = AVAudioPlayer.FromUrl (destinationURL, out error);
			if (player == null) {
				Debug.Print ("AVAudioPlayer failed: {0}", error);
				updateUI ();
				return;
			} 

			player.DecoderError += delegate {
				Debug.WriteLine ("DecoderError");
				updateUI ();
			};

			player.BeginInterruption += delegate {
				Debug.WriteLine ("BeginInterruption");
				player.Stop ();
				updateUI ();
			};

			player.FinishedPlaying += delegate(object sender, AVStatusEventArgs e) {
				Debug.WriteLine ("FinishedPlaying");
				updateUI ();
				player = null;
			};

			if (!player.Play ()) {
				Debug.WriteLine ("ERROR: Cannot play the file");
				updateUI ();
				player = null;
			}
		}
예제 #21
0
 public void Stop()
 {
     _player.Stop();
 }
예제 #22
0
 void AudioPlayer.StopAudio()
 {
     Player.Stop();
 }
예제 #23
0
 public Task StopPlaying()
 {
     Player?.Stop();
     return(Task.CompletedTask);
 }