protected override void OnCreate (Bundle bundle)
		{
			base.OnCreate (bundle);

			// Carega o layout "main" na view principal
			SetContentView (Resource.Layout.Main);

			// Pega o botão do recurso de layout e coloca um evento nele
			Button button = FindViewById<Button> (Resource.Id.button);

			vv = FindViewById<VideoView> (Resource.Id.video_view);
			pb = FindViewById<ProgressBar> (Resource.Id.progress_bar);
			MediaController mc = new MediaController(this);
			mp = new MediaPlayer ();

			pb.SetOnTouchListener (this);

			var uri = Android.Net.Uri.Parse ("http://3gpfind.com/vid/load/Movie%20Trailer/Predators(3gpfind.com).3gp");
			vv.SetOnPreparedListener (this);
			vv.SetVideoURI(uri);
			vv.SetMediaController(mc);
			mc.SetMediaPlayer(vv);
			mc.SetAnchorView(vv);

			button.Click += delegate {
				mc.Show();
				if (!ready)
				{
					holder = vv.Holder;
					holder.SetType (SurfaceType.PushBuffers);
					holder.AddCallback(this);
					mp.SetDataSource(this, uri);
					mp.SetOnPreparedListener(this);
					mp.Prepare();
					ready = true;
				}

				mp.Start();
//				vv.Start();

				Toast.MakeText (this, "Video Started", ToastLength.Short).Show ();
			};
		}
        public Task PlaySoundAsync(string filename)
        {
            // Create media player
            var player = new MediaPlayer();

            // Create task completion source to support async/await
            var tcs = new TaskCompletionSource<bool> ();

            // Open the resource
            var fd = Xamarin.Forms.Forms.Context.Assets.OpenFd (filename);

            // Hook up some events
            player.Prepared += (s, e) => {
                player.Start();
            };

            player.Completion += (sender, e) => {
                tcs.SetResult(true);
            };

            // Initialize
            player.SetDataSource (fd.FileDescriptor);
            player.Prepare ();

            return tcs.Task;
        }
        bool PreparePlayer()
        {
            if (player != null)
            {
                player.Prepare();
                Loop = true;

                playbackParams = new PlaybackParams();
                //playbackParams.SetSpeed(1.0f);
                player.PlaybackParams = playbackParams;

                return(true);
            }

            return(false);
        }
        public void OnSurfaceTextureAvailable(SurfaceTexture surface, int width, int height)
        {
            nn_surface = new Surface (surface);

            RelativeLayout.LayoutParams l;
            DisplayMetrics metrics = new DisplayMetrics();
            nn_activity.WindowManager.DefaultDisplay.GetMetrics(metrics);
            l = new RelativeLayout.LayoutParams(metrics.HeightPixels, metrics.WidthPixels);
            l.AddRule(LayoutRules.CenterInParent);
            float scale = (metrics.HeightPixels * 1.0f) / (metrics.WidthPixels * 1.0f);
            textureview.ScaleX = scale;
            textureview.LayoutParameters=l;

            try {
                nn_mediaplayer= new MediaPlayer();
                //String uriPath = "android.resource://"+nn_activity.PackageName+"/raw/Tap5050_About";
                nn_mediaplayer.SetDataSource(nn_activity,global::Android.Net.Uri.Parse("android.resource://"+nn_activity.PackageName +"/"+ Resource.Raw.Tap5050_About));
                nn_mediaplayer.SetSurface(nn_surface);
                nn_mediaplayer.Prepare();
                nn_mediaplayer.Prepared+= (object sender, EventArgs e) => {
                    (sender as MediaPlayer).Start ();
                };
                nn_mediaplayer.Completion+= (object sender, EventArgs e) => {
                    (sender as MediaPlayer).SeekTo (0);
                    (sender as MediaPlayer).Pause ();
                };

            }catch(Exception e){
                Toast.MakeText (nn_activity,"Sorry,Can not play the video",ToastLength.Long).Show();
            }
        }
 /// <summary>
 /// Method that plays the sound on Android.
 /// </summary>
 public void PlaySound(SoundboardItem item)
 {
     player = new MediaPlayer ();
     var fd = Xamarin.Forms.Forms.Context.Assets.OpenFd (item.FileName + ".mp3");
     player.SetDataSource (fd.FileDescriptor);
     player.Prepare ();
     player.Start ();
 }
Esempio n. 6
0
 public override void Play(string filename)
 {
     AssetFileDescriptor afd = Assets.OpenFd(filename);
     player = new MediaPlayer();
     player.SetDataSource(afd.FileDescriptor, afd.StartOffset, afd.Length);
     player.Completion += DidFinishPlaying;
     player.Prepare();
     player.Start();
 }
Esempio n. 7
0
 public int videoDuration(string filename)
 {
     MediaPlayer video = new MediaPlayer();
     FileInputStream fs = new FileInputStream(filename);
     FileDescriptor fd = fs.FD;
     video.SetDataSource(fd);
     video.Prepare();
     int length = video.Duration;
     video.Reset();
     video.Release();
     return length;
 }
Esempio n. 8
0
 public int findDuration(string filename)
 {
     MediaPlayer wav = new MediaPlayer();
     FileInputStream fs = new FileInputStream(filename);
     FileDescriptor fd = fs.FD;
     wav.SetDataSource(fd);
     wav.Prepare();
     int length = wav.Duration;
     wav.Reset();
     wav.Release();
     return length;
 }
Esempio n. 9
0
 public void Play(string p_FilePath)
 {
     using (MediaPlayer player = new MediaPlayer()) {
         if (p_FilePath.IndexOf ("Content") > -1) {
             Android.Content.Res.AssetFileDescriptor af = Android.App.Application.Context.Assets.OpenFd (p_FilePath);
             player.SetDataSource (af.FileDescriptor, af.StartOffset, af.Length);
         } else {
             player.SetDataSource (Path.Combine(DataPath,p_FilePath));
         }
         player.Prepare ();
         player.Start ();
     }
 }
Esempio n. 10
0
        public Media_player(File file)
        {
            music_File = file;

            if (isPlay)
            {
                Dispose();
            }

            player = new Android.Media.MediaPlayer();
            player.SetDataSource(music_File.AbsolutePath);
            player.Prepare();
        }
Esempio n. 11
0
        public async override void play(bool alone)
        {
            try
            {
                setStemSounds();
                string soundResult = propStemSounds[(propValue / 10) - 1];
                if (alone == false)
                {
                    soundResult = propStemSounds[9 + (propValue / 10) - 1];
                }

                if (player == null)
                {
                    player = player ?? new MediaPlayer();
                }
                else
                {
                    player.Reset();
                }

                new System.Threading.Thread(async() => {
                    await player1.SetDataSourceAsync(soundResult);

                    player1.Prepare();
                    player1.Start();
                }).Start();

                byte[] TotalBytes  = System.IO.File.ReadAllBytes(soundResult);
                double bitrate     = (BitConverter.ToInt32(new[] { TotalBytes[28], TotalBytes[29], TotalBytes[30], TotalBytes[31] }, 0) * 8);
                double duration    = (TotalBytes.Length - 8) * 8 / bitrate;
                int    durationInt = Convert.ToInt32(duration * 1000);
                System.Threading.Thread.Sleep(durationInt);

                if (player1 == null)
                {
                    player1 = player1 ?? new MediaPlayer();
                }
                else
                {
                    player1.Reset();
                }

                await player.SetDataSourceAsync(soundResult);

                //player.Prepare();
                //player.Start();
            }
            catch (Exception e)
            { }
        }
Esempio n. 12
0
        public void OnCompletion(AndroidMediaPlayer mp)
        {
            MediaEnded?.Invoke(this, null);
            PlaybackSession.PlaybackState = MediaPlaybackState.None;

            // Play next item in playlist, if any
            if (_playlistItems != null && _playlistIndex < _playlistItems.Count - 1)
            {
                _player.Reset();
                SetVideoSource(_playlistItems[++_playlistIndex]);
                _player.Prepare();
                _player.Start();
            }
        }
Esempio n. 13
0
		void play(string fullPath)
		{
			ISurfaceHolder holder = videoView.Holder;
			holder.SetType (SurfaceType.PushBuffers);
			holder.AddCallback( this );
			player = new  MediaPlayer ();
			Android.Content.Res.AssetFileDescriptor afd = this.Assets.OpenFd(fullPath);
			if  (afd != null )
			{
				player.SetDataSource (afd.FileDescriptor, afd.StartOffset, afd.Length);
				player.Prepare ();
				player.Start ();
			}
		}
Esempio n. 14
0
 public AndroidMusic(AssetFileDescriptor afd)
 {
     this.mp = new MediaPlayer ();
     try {
         mp.SetDataSource(afd.FileDescriptor, afd.StartOffset, afd.Length);
         mp.Prepare();
         isPrepared = true;
         mp.SetOnCompletionListener(this);
         mp.SetOnSeekCompleteListener(this);
         mp.SetOnPreparedListener(this);
         mp.SetOnVideoSizeChangedListener(this);
     } catch {
         throw new ApplicationException("Couldn't load music");
     }
 }
		public void PlayAudioFile(string fileName)
		{
			var player = new MediaPlayer();
			var fd = global::Android.App.Application.Context.Assets.OpenFd(fileName);
			player.Prepared += (s, e) =>
			{
				player.Start();
			};

			player.Completion += (s, e) =>
			{
			};

			player.SetDataSource(fd.FileDescriptor, fd.StartOffset, fd.Length);
			player.Prepare();
		}
Esempio n. 16
0
        public void StartVideoPlayback(SurfaceView surface, string FilePath)
        {
            if (_player != null)
              {
            StopVideoPlayback();
              }
              _player = new MediaPlayer();

              ISurfaceHolder holder = surface.Holder;
              holder.SetType(Android.Views.SurfaceType.PushBuffers);
              holder.SetFixedSize(400, 300);

              _player.SetDisplay(holder);
              _player.SetDataSource(FilePath);
              _player.Prepare();
              _player.Start();
        }
Esempio n. 17
0
 public void playAudio(string filePath)
 {
     if (player == null)
     {
         player = new MediaPlayer();
         player.SetDataSource(filePath);
         player.Prepare();
         player.Start();
     }
     else
     {
         player.Reset();
         player.SetDataSource(filePath);
         player.Prepare();
         player.Start();
     }
     isPlaying = true;
 }
Esempio n. 18
0
        public AndroidMusic(AssetFileDescriptor assetDescriptor)
        {
            mediaPlayer = new MediaPlayer();
            try
            {
                mediaPlayer.SetDataSource(assetDescriptor.FileDescriptor,
                                          assetDescriptor.StartOffset,
                                          assetDescriptor.Length);
                mediaPlayer.Prepare();
                isPrepared = true;
                mediaPlayer.SetOnCompletionListener(this);
                mediaPlayer.SetOnSeekCompleteListener(this);
                mediaPlayer.SetOnPreparedListener(this);
                mediaPlayer.SetOnVideoSizeChangedListener(this);

            }
            catch (Exception e)
            {
                throw new SystemException("Couldn't load music");
            }
        }
Esempio n. 19
0
 public void Play(int resId)
 {
     try
     {
         if (player != null)
         {
             //if (player.IsPlaying)
             //{
             //    player.Stop();
             //    player.Reset();
             //}
             player.Reset();
         }
         player = MediaPlayer.Create(Application.Context, resid: resId);
         player.Stop();
         player.Prepare();
         player.Start();
     }
     catch (Exception ex)
     {
         System.Console.Out.WriteLine(ex.StackTrace);
     }
 }
Esempio n. 20
0
 internal void ProcessPlay()
 {
     DrawCommon("XXXXX");
     if (smf_music == null)
         return;
     if (media_player == null) {
         try {
             media_player = new MediaPlayer ();
             media_player.SetDataSource(jetfile.FullName);
             media_player.Prepare();
         } catch (IOException ex) {
             media_player = null;
             DrawCommon ("failed to load SMF");
             return;
         }
     }
     if (midi_player == null) {
         midi_player = new MidiPlayer (smf_music);
         midi_player.Finished += delegate { StopViews(); };
         midi_player.MessageReceived += HandleSmfMessage;
     }
     // This state check is not necessary for MidiPlayer,
     // but for JetPlayer (which does not expose state).
     if (midi_player.State != PlayerState.Playing) {
         midi_player.PlayAsync();
         media_player.Start();
     }
     DrawCommon ("PLAY");
 }
Esempio n. 21
0
        void InitBeepSound()
        {
            if(playBeep && mediaPlayer == null)
            {
                VolumeControlStream = Android.Media.Stream.Music;
                mediaPlayer = new MediaPlayer();
                mediaPlayer.SetAudioStreamType(Android.Media.Stream.Music);
                mediaPlayer.SetOnCompletionListener(beepListener);

                var file = Resources.OpenRawResourceFd(BeepResource);
                try{
                    mediaPlayer.SetDataSource(file.FileDescriptor, file.StartOffset, file.Length);

                    file.Close();
                    mediaPlayer.SetVolume(0.1f, 0.1f);
                    mediaPlayer.Prepare();
                }
                catch(Java.IO.IOException e)
                {
                    mediaPlayer = null;
                }
            }
        }
		void PlaySound (string customSound)
		{
			if (_ringtone != null) {
				return;
			}           

//			_ringtone = RingtoneManager.GetRingtone (Application.Context, sound);
//			_ringtone.Play ();

			try {
				var sound = GetRingtoneUri (customSound);

				_ringtone = new MediaPlayer ();
				_ringtone.SetDataSource (this, sound);

				_ringtone.SetAudioStreamType (Stream.Alarm);

				_ringtone.Looping = true;
				_ringtone.Prepare ();
				_ringtone.Start ();
			} catch {
			}   
		}
Esempio n. 23
0
        void play(string fullPath)
        {
            ISurfaceHolder holder = _tv.Holder;
            holder.SetType (SurfaceType.PushBuffers);
            // Necesito saber cuando la superficie esta creada para poder asignar el Display al MediaPlayer
            holder.AddCallback (this);
            _player = new MediaPlayer();

            Android.Content.Res.AssetFileDescriptor afd = this.Assets.OpenFd(fullPath);
            if (afd != null)
            {
            _player.SetDataSource(afd.FileDescriptor, afd.StartOffset, afd.Length);
            _player.Prepare ();

            _player.Start();
            }
        }
Esempio n. 24
0
        //Used for entering the Mandarin_ma speech processing screen
        void HandleMandarin_Ma_Male_Select()
        {
            SetContentView (Resource.Layout.Mandarin_Mother_Male);

            string RecordPath = "/sdcard/Recording.mp3";
            //string RecordPath = Environment.getExternalStorageDirectory ()
            //	.getAbsolutePath () + "/Recording.mp3";

            //string RecordPath = Android.OS.Environment.ExternalStorageDirectory.AbsolutePath + "/Recording.3gpp";
            //string RecordPath = this.file.getAbsolutePath().substring(8)

            Button PlayStock = FindViewById<Button> (Resource.Id.PlayMa);
            PlayBack = FindViewById<Button> (Resource.Id.PlayBack);
            Button BackToMandarin = FindViewById<Button> (Resource.Id.BackToMandarin);

            RecordVoice = FindViewById<Button> (Resource.Id.Record);
            StopRecord = FindViewById<Button> (Resource.Id.Stop);
            StockPlayer = MediaPlayer.Create(this, Resource.Raw.mother);

            _recorder = new MediaRecorder ();
            _player = new MediaPlayer ();

            //Click Event Handlers
            PlayStock.Click += delegate {
                StockPlayer.Start();
            };

            RecordVoice.Click += delegate {

                RecordVoice.Enabled = !RecordVoice.Enabled;
                StopRecord.Enabled = !StopRecord.Enabled;
                if (PlayBack.Enabled==true){
                    PlayBack.Enabled = false;
                }

                _recorder.SetAudioSource (AudioSource.Mic);
                _recorder.SetOutputFormat (OutputFormat.Mpeg4);
                _recorder.SetOutputFile(RecordPath);
                _recorder.SetAudioEncoder (AudioEncoder.Aac);

                _recorder.Prepare();
                _recorder.Start ();

            };

            //Stops recording
            StopRecord.Click += delegate {
                StopRecord.Enabled =! StopRecord.Enabled;

                if (PlayBack.Enabled==false){
                    PlayBack.Enabled = true;
                }

                _recorder.Stop ();
                _recorder.Reset ();

                /* For instant playback
                _player.SetDataSource (RecordPath);
                _player.Prepare ();
                _player.Start ();
                */
                RecordVoice.Enabled = !RecordVoice.Enabled;

            };

            PlayBack.Click += delegate {
                RecordPlayer = new MediaPlayer ();
                RecordPlayer.SetDataSource (RecordPath);
                RecordPlayer.Prepare ();
                RecordPlayer.Start ();

            };

            BackToMandarin.Click += delegate {
                HandleMandarinSelect ();
            };
        }
Esempio n. 25
0
    protected async override void OnCreate(Bundle bundle)
    {
      base.OnCreate(bundle);

      SetContentView(Resource.Layout.PodcastDetail);

      var showNumber = Intent.GetIntExtra("show_number", 0);
      episode = Activity1.ViewModel.GetPodcast(showNumber);


      var description = FindViewById<TextView>(Resource.Id.descriptionView);
      description.Text = episode.Description;

      var play = FindViewById<Button>(Resource.Id.playButton);
      var pause = FindViewById<Button>(Resource.Id.pauseButton);
      var stop = FindViewById<Button>(Resource.Id.stopButton);
      seekBar = FindViewById<SeekBar>(Resource.Id.seekBar1);
      status = FindViewById<TextView>(Resource.Id.statusText);
      updateHandler = new Handler();

      player = new MediaPlayer();
      player.SetDataSource(this, Android.Net.Uri.Parse(episode.AudioUrl));
      player.PrepareAsync();

      player.Prepared += (sender, e) =>
          {
            initialized = true;
            player.SeekTo(timeToSet * 1000);
            UpdateStatus();
          };

      play.Click += (sender, e) =>
      {
        player.Start();
        updateHandler.PostDelayed(UpdateStatus, 1000);
      };

      pause.Click += (sender, e) => player.Pause();

      stop.Click += (sender, e) =>
      {
        player.Stop();
        player.Reset();
        player.SetDataSource(this, Android.Net.Uri.Parse(episode.AudioUrl));
        player.Prepare();
      };

      seekBar.ProgressChanged += (sender, e) =>
          {
            if (!e.FromUser)
              return;

            player.SeekTo((int)(player.Duration * ((float)seekBar.Progress / 100.0)));
          };

      var updated = await episode.GetTimeAsync();

      if (updated == null || updated.ShowNumber != episode.ShowNumber)
        return;

      if (initialized && player != null)
      {
        player.SeekTo(updated.CurrentTime * 1000);
        UpdateStatus();
      }
      else
      {
        timeToSet = updated.CurrentTime;
      }
    }
Esempio n. 26
0
        public string SoundPlay(string SoundName, string messageid, string messegeCondition, string status, string CurrentSliderValue)
        {
            try
            {
                if (SoundName == "served")
                {
                    player = new Android.Media.MediaPlayer();
                    var ffd = Xamarin.Forms.Forms.Context.Assets.OpenFd("served.mp3");
                    player.Reset();
                    player.Prepared += (s, e) => { player.Start(); };
                    player.SetDataSource(ffd.FileDescriptor);
                    player.Prepare();
                }
                else
                {
                    if (status == "Play")
                    {
                        player = new Android.Media.MediaPlayer();
                        player.Reset();
                        player.Prepared += (s, e) => { player.Start(); };
                        player.SetDataSource(SoundName);
                        player.Prepare();
                        Messageid = messageid;
                        if (messegeCondition == "right_audio")
                        {
                            TimerSound          = new System.Timers.Timer();
                            TimerSound.Interval = 1000;
                            TimerSound.Elapsed += TimerSound_Elapsed;
                            TimerSound.Start();
                        }
                        else
                        {
                            TimerSound          = new System.Timers.Timer();
                            TimerSound.Interval = 1000;
                            TimerSound.Elapsed += TimerSound_ElapsedSlider;
                            TimerSound.Start();
                        }
                    }
                    else if (status == "Stop")
                    {
                        player.Stop();
                        TimerSound.Stop();
                    }
                    else if (status == "Pause")
                    {
                        player.Pause();
                        TimerSound.Stop();
                    }
                    else if (status == "PauseAfterplay")
                    {
                        try
                        {
                            var Converter    = CurrentSliderValue.Substring(0, CurrentSliderValue.Length - 3);;
                            int CurrentValue = 0;
                            CurrentValue = Int32.Parse(Converter);
                            player.SeekTo(CurrentValue);
                            player.Start();
                            TimerSound.Start();
                        }
                        catch (Exception)
                        {
                        }
                    }
                }

                return(player.Duration.ToString());
            }
            catch (Exception)
            {
                return(null);
            }
        }