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();
            }
        }