public void SurfaceCreated(ISurfaceHolder holder) { _player?.SetDisplay(holder); _player?.SetScreenOnWhilePlaying(true); _hasValidHolder = true; UpdateVideoStretch(_currentStretch); }
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(); }
private void InitializePlayer() { _player = new AndroidMediaPlayer(); var surfaceView = RenderSurface as SurfaceView; if (_hasValidHolder) { _player.SetDisplay(surfaceView.Holder); _player.SetScreenOnWhilePlaying(true); } else { surfaceView.Holder.AddCallback(this); } _player.SetOnErrorListener(this); _player.SetOnPreparedListener(this); _player.SetOnSeekCompleteListener(this); _player.SetOnBufferingUpdateListener(this); PlaybackSession.PlaybackStateChanged -= OnStatusChanged; PlaybackSession.PlaybackStateChanged += OnStatusChanged; }
private void PlayVideo(int Media) { DoCleanUp(); try { switch (Media) { case LOCAL_VIDEO: // // * TODO: Set the path variable to a local media file path. // path = "http://172.16.101.100:81/video/123.mp4"; if (path == "") { // Tell the user to provide a media file URL. Toast.MakeText(this, "Please edit MediaPlayerDemo_Video Activity, " + "and set the path variable to your media file path." + " Your media file must be stored on sdcard.", ToastLength.Long).Show(); return; } break; case STREAM_VIDEO: // // * TODO: Set path variable to progressive streamable mp4 or // * 3gpp format URL. Http protocol should be used. // * Mediaplayer can only play "progressive streamable // * contents" which basically means: 1. the movie atom has to // * precede all the media data atoms. 2. The clip has to be // * reasonably interleaved. // * // path = "http://172.16.101.100:81/video/123.mp4"; if (path == "") { // Tell the user to provide a media file URL. Toast.MakeText(this, "Please edit MediaPlayerDemo_Video Activity," + " and set the path variable to your media file URL.", ToastLength.Long).Show(); return; } break; } // Create a new media player and set the listeners mMediaPlayer = new MediaPlayer(this); mMediaPlayer.SetDataSource(path); mMediaPlayer.SetDisplay(holder); mMediaPlayer.PrepareAsync(); mMediaPlayer.SetOnBufferingUpdateListener(this); mMediaPlayer.SetOnCompletionListener(this); mMediaPlayer.SetOnPreparedListener(this); mMediaPlayer.SetOnVideoSizeChangedListener(this); VolumeControlStream = Stream.Music; } catch (Exception e) { Log.Error(TAG, "error: " + e.Message, e); } }
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 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(); } }