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 virtual void Play() { if (Source == null || _player == null) { return; } try { // If we reached the end of media, we need to reset position to 0 if (PlaybackSession.PlaybackState == MediaPlaybackState.None) { PlaybackSession.Position = TimeSpan.Zero; } _isPlayRequested = true; if (_isPlayerPrepared) { _player.Start(); PlaybackSession.PlaybackState = MediaPlaybackState.Playing; } } catch (global::System.Exception ex) { OnMediaFailed(ex); } }
protected override void OnCreate(Bundle bundle) { base.OnCreate(bundle); ActionBar.Hide(); SetContentView(Resource.Layout.Main); cover = FindViewById<RelativeLayout>(Resource.Id.titleScreen); player = MediaPlayer.Create(this, Resource.Raw.avril_14th); toggleMusic = FindViewById<ToggleButton>(Resource.Id.toggleMusic); player.Start(); player.Looping = true; cover.Click += delegate { StartActivity(typeof(Login)); }; toggleMusic.Click += (o, s) => { if (toggleMusic.Checked) { player.Start(); toggleMusic.SetBackgroundResource(Android.Resource.Drawable.IcMediaPause); } else { toggleMusic.SetBackgroundResource(Android.Resource.Drawable.IcMediaPlay); player.Pause(); } }; }
public override View OnCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { View view = inflater.Inflate(Resource.Layout.HomeScreen, container, false); infoButton = view.FindViewById<Button>(Resource.Id.infoButton); player = MediaPlayer.Create(view.Context, Resource.Raw.avril_14th); toggleMusic = view.FindViewById<ToggleButton>(Resource.Id.toggleMusic); cover = view.FindViewById<RelativeLayout>(Resource.Id.titleScreen); Xamarin.Insights.Initialize(XamarinInsights.ApiKey, view.Context); CurrentPlatform.Init(); player.Start(); player.Looping = true; cover.Click += delegate { facebookLogin.Invoke(this, new LoginEventArgs()); }; toggleMusic.Click += (o, s) => { if (toggleMusic.Checked) { player.Start(); toggleMusic.SetBackgroundResource(Android.Resource.Drawable.IcMediaPause); } else { toggleMusic.SetBackgroundResource(Android.Resource.Drawable.IcMediaPlay); player.Pause(); } }; return view; }
public override void OnProgressChanged(WebView view, int newProgress) { base.OnProgressChanged(view, newProgress); _context.SetProgress(newProgress * 100); if (newProgress == 100) { _context.Title = view.Title; bool soundEnabled = PreferenceManager.GetDefaultSharedPreferences(_context.ApplicationContext).GetBoolean("sounds", false); if (soundEnabled) { _mediaPlayer = MediaPlayer.Create(_context.ApplicationContext, Resource.Raw.inception_horn); _mediaPlayer.Completion += delegate { _mediaPlayer.Release(); }; _mediaPlayer.Start(); } // add this page to the history using (SQLiteDatabase db = _historyDataHelper.WritableDatabase) { var values = new ContentValues(); values.Put("Title", view.Title); values.Put("Url", view.Url); values.Put("Timestamp", DateTime.Now.Ticks); db.Insert("history", null, values); } } else { _context.Title = _context.ApplicationContext.Resources.GetString(Resource.String.title_loading); } }
protected override void OnElementChanged(ElementChangedEventArgs<Frame> e) { base.OnElementChanged(e); if (Element == null) return; player = new MediaPlayer(); timer = new Timer(1000); timer.Elapsed += timer_Elapsed; player.Prepared += (sender, args) => { try { player.SeekTo(0); player.Start(); timer.Start(); } catch { } }; if (string.IsNullOrWhiteSpace(Player.Url)) return; InitPlayer(); }
public bool PlayWavFile(string fileName) { _mediaPlayer = MediaPlayer.Create(global::Android.App.Application.Context, Resource.Raw.ding_persevy); _mediaPlayer.Start(); return true; }
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; }
public virtual void PyayerMedia() { _mediaPlayer = Android.Media.MediaPlayer.Create(context, Resource.Drawable.error); _mediaPlayer.Start(); //IOnCompletionListener onCompletion=new IMediaPlayerCompletion(); //onCompletion.OnCompletion(_mediaPlayer); //_mediaPlayer.SetOnCompletionListener(onCompletion); }
/// <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 (); }
protected override void OnCreate (Bundle savedInstanceState) { base.OnCreate (savedInstanceState); // Create your application here SetContentView(Resource.Layout.Menu); mpButtonTap = MediaPlayer.Create (this, Resource.Raw.buttontap); mimgSlogan = FindViewById<ImageView> (Resource.Id.limgMenuSlogan); mimgSlogan.SetImageResource (Resource.Drawable.slogan); mimgCoin = FindViewById<ImageView> (Resource.Id.limgCoinIcon); mimgCoin.SetImageResource (Resource.Drawable.coin_small); mbtnPlay = FindViewById<Button> (Resource.Id.lbtnPlay); mbtnPhrases = FindViewById<Button> (Resource.Id.lbtnPhrases); mbtnDictionary = FindViewById<Button> (Resource.Id.lbtnDictionary); mbtnAchievements = FindViewById<Button> (Resource.Id.lbtnAchievements); mtxtTip = FindViewById<TextView> (Resource.Id.ltxtTip); mtxtCoin = FindViewById<TextView> (Resource.Id.ltxtCoin); Database.createDatabase ("Tip"); Database.createDatabase("Coins"); Database.createDatabase ("Dictionary"); Database.createDatabase ("Phrases"); mtxtCoin.Text = Convert.ToString(Database.getCoins ()); mtxtTip.Text = Database.getRandomTip(); mbtnPlay.Click += (object sender, EventArgs e) => { mpButtonTap.Start (); StartActivity(typeof(actGame)); }; mbtnPhrases.Click += (object sender, EventArgs e) => { mpButtonTap.Start (); StartActivity(typeof(actPhrases)); }; mbtnDictionary.Click += (object sender, EventArgs e) => { mpButtonTap.Start (); StartActivity(typeof(actDictionary)); }; mbtnAchievements.Click += (object sender, EventArgs e) => { mpButtonTap.Start (); }; }
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(); }
protected override void OnCreate(Bundle bundle) { base.OnCreate(bundle); player = Android.Media.MediaPlayer.Create(this, Resource.Raw.SampleAudio); SetContentView(Resource.Layout.Main); mAudioManager = (AudioManager)GetSystemService(Context.AudioService); maxVolume = mAudioManager.GetStreamMaxVolume(Stream.Music); onVolumeChangeListener(); player.Start(); }
public void OnSensorChanged(SensorEvent e) { if (!mp.IsPlaying) { mp.Start(); } else { mp.Pause(); } }
public bool Play() { _player = MediaPlayer.Create(global::Android.App.Application.Context, Resource.Raw._01yes); _player.Start(); _player.Completion += delegate { _player.Release(); }; return true; }
public void OnSensorChanged(SensorEvent e) { if (!mp.IsPlaying) { mp.Start(); text.Text = "on"; } else { mp.Pause(); text.Text = "off"; } }
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 (); } }
public void StartPlayer(String filePath) { if (player == null) { player = new MediaPlayer(); } else { player.Reset(); player = MediaPlayer.Create(this, Resource.Raw.buffy); // player.SetDataSource(filePath); //player.Prepare(); player.Start(); } }
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) { } }
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 (); } }
public static void Start() { if (getFocus() == AudioFocusRequest.Granted) { if (player != null) { player.Start(); isPlay = true; isPause = false; isStop = false; } } ; }
protected override void OnCreate(Bundle bundle) { base.OnCreate (bundle); SetContentView (Resource.Layout.Main); _player = MediaPlayer.Create(this, Resource.Raw.test); var playButton = FindViewById<Button> (Resource.Id.playButton); playButton.Click += delegate { _player.Start(); }; }
private void ToggleMusic_Click(object sender, System.EventArgs e) { if (toggleMusic.Checked) { player.Release(); player = MediaPlayer.Create(this, Resource.Raw.avril_14th); player.Start(); player.Looping = true; toggleMusic.SetBackgroundResource(Android.Resource.Drawable.IcMediaPause); } else toggleMusic.SetBackgroundResource(Android.Resource.Drawable.IcMediaPlay); player.Stop(); }
public void Play(Context c) { if (mPlayer != null && !mPlayer.IsPlaying) { mPlayer.Start(); return; } Stop(); mPlayer = MediaPlayer.Create(c, Resource.Raw.one_small_step); mPlayer.Completion += (object sender, EventArgs e) => { Stop(); }; mPlayer.Start(); }
///<Summary> /// Begin playback or resume if paused ///</Summary> public void Play() { if (player == null) { return; } if (IsPlaying) { Pause(); Seek(0); } player.Start(); }
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(); }
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(); }
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; }
public void OnSensorChanged(SensorEvent e) { Toast.MakeText(this, "CHANGE", ToastLength.Long).Show(); play = !play; if (play) { if (!MP.IsPlaying) { MP.Start(); } Toast.MakeText(this, "START", ToastLength.Long).Show(); MP.SetVolume(0.0f, 1.0f); } else { MP.Pause(); Toast.MakeText(this, "STOP", ToastLength.Long).Show(); } }
protected override void OnCreate(Bundle savedInstanceState) { base.OnCreate (savedInstanceState); SetContentView (Resource.Layout.baseEyeBreak); ImageView img = FindViewById<ImageView> (Resource.Id.eyeImage); Button okay = FindViewById<Button> (Resource.Id.myEyeButton1); //play reminder sound player = new MediaPlayer(); player = MediaPlayer.Create (this, Resource.Raw.A); player.Start (); //Hackish, come up with better way when more time //Randomize which break reminder image is shown int imgSwitch = rand.Next (1, 5); switch (imgSwitch) { case 1: img.SetImageResource (Resource.Drawable.eye1); break; case 2: img.SetImageResource (Resource.Drawable.eye2); break; case 3: img.SetImageResource (Resource.Drawable.eye3); break; case 4: img.SetImageResource (Resource.Drawable.eye4); break; case 5: img.SetImageResource (Resource.Drawable.eye5); break; //Add more here as necessary default: break; }//end switch okay.Click += (object sender, EventArgs e) => { SetResult(Result.Ok); Finish(); }; }
void selectSoundListView_ItemClick(object sender, AdapterView.ItemClickEventArgs e) { if (_player != null && _player.IsPlaying) _player.Stop(); var selectedItem = _adapter.SourceItems[e.Position]; Settings.WakeUpSound = selectedItem.SoundName; _adapter.SourceItems.ForEach(i => { if (i.MyRadioButton != null) i.MyRadioButton.Checked = false; }); selectedItem.MyRadioButton.Checked = true; _adapter.NotifyDataSetChanged(); int resId = (int) typeof (Resource.Raw).GetField(Settings.WakeUpSound).GetValue(null); _player = MediaPlayer.Create(this, resId); _player.Start(); }
protected override void OnCreate(Bundle bundle) { _player = MediaPlayer.Create (this,Resource.Raw.police_alarm); base.OnCreate (bundle); SetContentView (Resource.Layout.alarm); ImageButton start = FindViewById<ImageButton> (Resource.Id.Start_ALarm); start.Click += delegate { _player = MediaPlayer.Create (this,Resource.Raw.police_alarm); _player.Start (); }; ImageButton stop = FindViewById<ImageButton> (Resource.Id.Stop_ALarm); stop.Click += delegate { _player.Stop (); _player.Release(); _player=null; // Intent i = new Intent (this, typeof(MainActivity)); // StartActivity (i); }; // FindViewById<TextView> (Resource.Id.Start_ALarm).Click+=Start_alarm_click; //FindViewById<TextView> (Resource.Id.Stop_ALarm).Click += Stop_alarm_click; }
private void IntializePlayer() { player = new MediaPlayer(); //Tell our player to sream music player.SetAudioStreamType(Stream.Music); //Wake mode will be partial to keep the CPU still running under lock screen player.SetWakeMode(ApplicationContext, WakeLockFlags.Partial); //When we have prepared the song start playback player.Prepared += (sender, args) => player.Start(); //When we have reached the end of the song stop ourselves, however you could signal next track here. player.Completion += (sender, args) => Stop(); player.Error += (sender, args) => { //playback error Console.WriteLine("Error in playback resetting: " + args.What); Stop();//this will clean up and reset properly. }; }
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); } }
public void reproducir(string downloadurl, bool desdecache) { // musicaplayer.SetDataSource(downloadurl); if (playeroffline.gettearinstancia() != null) { try { musicaplayer.Release(); musicaplayer = new MediaPlayer(); #pragma warning disable 414 if (Android.OS.Build.VERSION.SdkInt >= BuildVersionCodes.N) { musicaplayer.SetAudioAttributes(new AudioAttributes.Builder() .SetUsage(AudioUsageKind.Media) .SetContentType(AudioContentType.Music) .Build()); } else { #pragma warning disable CS0618 // El tipo o el miembro están obsoletos musicaplayer.SetAudioStreamType(Android.Media.Stream.Music); #pragma warning restore CS0618 // El tipo o el miembro están obsoletos } #pragma warning restore 414 musicaplayer.SetWakeMode(this, WakeLockFlags.Partial); #pragma warning disable 414 #pragma warning disable CS0618 // El tipo o el miembro están obsoletos var focusResult = audioManager.RequestAudioFocus(this, Stream.Music, AudioFocus.Gain); #pragma warning restore CS0618 // El tipo o el miembro están obsoletos #pragma warning restore 414 if (focusResult != AudioFocusRequest.Granted) { //could not get audio focus Console.WriteLine("Could not get audio focus"); } musicaplayer.Prepared += delegate { musicaplayer.Start(); if (this.desdecache) { musicaplayer.Pause(); } if (playeroffline.gettearinstancia() != null) { if (playeroffline.gettearinstancia().video.Visibility == ViewStates.Visible) { musicaplayer.SetDisplay(null); musicaplayer.SetDisplay(playeroffline.gettearinstancia().holder); } if (SettingsHelper.HasKey("posactual") && this.desdecache) { var posicion = 0; try { posicion = int.Parse(SettingsHelper.GetSetting("posactual")); musicaplayer.SeekTo(posicion); } catch (Exception) { } } } }; musicaplayer.Completion += delegate { playeroffline.gettearinstancia().RunOnUiThread(() => { playeroffline.gettearinstancia().RunOnUiThread(() => { playeroffline.gettearinstancia().siguiente.PerformClick(); }); }); }; musicaplayer.SetDataSource(this, Android.Net.Uri.Parse(downloadurl.Trim())); mostrarnotificacion(); musicaplayer.PrepareAsync(); } catch (Exception) { //if() playeroffline.gettearinstancia().RunOnUiThread(() => { Toast.MakeText(playeroffline.gettearinstancia(), "Error al reproducir", ToastLength.Long).Show(); }); } } else { musicaplayer.Reset(); StopSelf(); } }
public void OnStart(MediaPlayer player) { player.Start(); }
public void OnPrepared(MediaPlayer mp) { mp.Start(); SessionManager.UpdatePlaybackState(PlaybackStateCompat.StatePlaying, Position.Seconds); }
void IntializePlayer () { _player = new MediaPlayer (); // Tell our player to sream music _player.SetAudioStreamType (Stream.Music); // Wake mode will be partial to keep the CPU still running under lock screen _player.SetWakeMode (ApplicationContext, WakeLockFlags.Partial); // When we have prepared the song start playback _player.Prepared += (sender, args) => _player.Start (); // When we have reached the end of the song stop ourselves, however you could signal next track here. _player.Completion += (sender, args) => { Stop (); CurrentEpisode.CurrentTime = CurrentEpisode.Duration; DrunkAudibleApplication.Self.Database.InsertOrReplace (CurrentEpisode); if (NextEpisode != null) { NextEpisode.CurrentTime = 0; CurrentEpisode = NextEpisode; } }; _player.Error += (sender, args) => { // playback error Log.Debug (DEBUG_TAG, "Error in playback resetting: " + args.What); Stop ();//this will clean up and reset properly. }; }
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); } }
public void reproducir(string downloadurl) { // musicaplayer.SetDataSource(downloadurl); if (YoutubePlayerServerActivity.gettearinstancia() != null) { musicaplayer.Release(); musicaplayer = new MediaPlayer(); if (Android.OS.Build.VERSION.SdkInt >= BuildVersionCodes.N) { musicaplayer.SetAudioAttributes(new AudioAttributes.Builder().SetUsage(AudioUsageKind.Media).SetContentType(AudioContentType.Music).Build()); } else { #pragma warning disable CS0618 // El tipo o el miembro están obsoletos musicaplayer.SetAudioStreamType(Android.Media.Stream.Music); #pragma warning restore CS0618 // El tipo o el miembro están obsoletos } musicaplayer.SetWakeMode(this, WakeLockFlags.Partial); #pragma warning disable CS0618 // El tipo o el miembro están obsoletos var focusResult = audioManager.RequestAudioFocus(this, Stream.Music, AudioFocus.Gain); #pragma warning restore CS0618 // El tipo o el miembro están obsoletos // musicaplayer.SetVideoScalingMode(VideoScalingMode.ScaleToFitWithCropping); if (focusResult != AudioFocusRequest.Granted) { //could not get audio focus Console.WriteLine("Could not get audio focus"); } musicaplayer.Error += (aa, aaaa) => { Console.WriteLine("klk aw aw aw"); }; musicaplayer.Info += (aa, aaa) => { var instancia = YoutubePlayerServerActivity.gettearinstancia(); if (instancia != null) { switch (aaa.What) { case MediaInfo.BufferingStart: if (instancia.prgBuffering.Visibility != ViewStates.Visible) { instancia.prgBuffering.Visibility = ViewStates.Visible; } break; case MediaInfo.BufferingEnd: if (instancia.prgBuffering.Visibility != ViewStates.Gone) { instancia.prgBuffering.Visibility = ViewStates.Gone; } break; case MediaInfo.VideoRenderingStart: if (instancia.prgBuffering.Visibility != ViewStates.Gone) { instancia.prgBuffering.Visibility = ViewStates.Gone; } break; } ; } }; musicaplayer.Prepared += delegate { if (YoutubePlayerServerActivity.gettearinstancia().videoon) { YoutubePlayerServerActivity.gettearinstancia().RunOnUiThread(() => { try { musicaplayer.SetDisplay(null); musicaplayer.SetDisplay(YoutubePlayerServerActivity.gettearinstancia().videoSurfaceHolder); } catch (Exception) { } YoutubePlayerServerActivity.gettearinstancia().SetVideoSize(); }); } musicaplayer.Start(); if (YoutubePlayerServerActivity.gettearinstancia().qualitychanged) { try { YoutubePlayerServerActivity.gettearinstancia().qualitychanged = false; musicaplayer.SeekTo(YoutubePlayerServerActivity.gettearinstancia().previousprogress); } catch (Exception) { } } }; musicaplayer.Completion += delegate { if ((musicaplayer.Duration > 5 && musicaplayer.CurrentPosition > 5)) { new Thread(() => { YoutubePlayerServerActivity.gettearinstancia().NextVideo(); }).Start(); } }; mostrarnotificacion(); musicaplayer.SetDataSource(this, Android.Net.Uri.Parse(downloadurl)); musicaplayer.PrepareAsync(); } else { musicaplayer.Reset(); StopSelf(); } }
protected override void OnCreate(Bundle bundle) { base.OnCreate (bundle); SetContentView (Resource.Layout.Lesson); _play_word = FindViewById<Button> (Resource.Id.currentWord); _play_word.Click += delegate { if(!playing) { _player = MediaPlayer.Create (this, Resource.Raw.test); _player.Start (); playing = true; } else { _player.Stop (); playing = false; } }; _record_button = FindViewById<Button> (Resource.Id.record_button); //string path = "/sdcard/recording.3gpp"; //location to temporarily hold recorded file string path = Android.OS.Environment.ExternalStorageDirectory.AbsolutePath + "/test.3gpp"; //mFileName = Android.OS.Environment.GetExternalStoragePublicDirectory().AbsolutePath(); //mFileName += "/audiorecordtest.3gpp"; _record_button.Click += delegate { //first press of Speak button starts recording, secodn press stops //record_button.Enabled = !record_button.Enabled; if (!recording) { _recorder.SetAudioSource (AudioSource.Mic); _recorder.SetOutputFormat (OutputFormat.ThreeGpp); _recorder.SetAudioEncoder (AudioEncoder.AmrNb); _recorder.SetOutputFile (path); _recorder.Prepare (); _recorder.Start (); recording = true; } else { _recorder.Stop (); _recorder.Reset (); recording = false; recording_made = true; } }; _playback_button = FindViewById<Button> (Resource.Id.listen_button); _playback_button.Click += delegate { //Pressing Listen button cuases the user recodeing to play back if(recording_made) { _player.SetDataSource (path); _player.Prepare (); _player.Start (); } else if(playing) { _player.Stop (); playing = false; } else { _player = MediaPlayer.Create(this, Resource.Raw.test); _player.Start (); playing = true; } }; }
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; } }