Exemplo n.º 1
0
		public Playback(MusicService service, MusicProvider musicProvider) {
			this.service = service;
			this.musicProvider = musicProvider;
			audioManager = (AudioManager) service.GetSystemService(Context.AudioService);
			wifiLock = ((WifiManager) service.GetSystemService(Context.WifiService))
				.CreateWifiLock(WifiMode.Full, "sample_lock");
			mAudioNoisyReceiver.OnReceiveImpl = (context, intent) => {
				if (AudioManager.ActionAudioBecomingNoisy == intent.Action) {
					LogHelper.Debug(Tag, "Headphones disconnected.");
					if (IsPlaying) {
						var i = new Intent(context, typeof(MusicService));
						i.SetAction(MusicService.ActionCmd);
						i.PutExtra(MusicService.CmdName, MusicService.CmdPause);
						service.StartService(i);
					}
				}
			};
		}
Exemplo n.º 2
0
        /// <summary>
        /// This will release the wifi lock if it is no longer needed
        /// </summary>
        void ReleaseWifiLock ()
        {
            if (_wifiLock == null)
            {
                return;
            }

            _wifiLock.Release ();
            _wifiLock = null;
        }
Exemplo n.º 3
0
 /// <summary>
 /// Lock the wifi so we can still stream under lock screen
 /// </summary>
 void AquireWifiLock ()
 {
     if (_wifiLock == null)
     {
         _wifiLock = _wifiManager.CreateWifiLock (Net.WifiMode.Full, "xamarin_wifi_lock");
     } 
     _wifiLock.Acquire ();
 }
        /// <summary>
        /// This will release the wifi lock if it is no longer needed
        /// </summary>
        public void ReleaseWifiLock()
        {
            try
            {
                if (wifiLock == null || !wifiLock.IsHeld)
                    return;
                wifiLock.Release();
            }
            catch (Java.Lang.RuntimeException ex)
            {
                Console.WriteLine(ex.Message);
            }

            wifiLock = null;
        }
 /// <summary>
 /// Lock the wifi so we can still stream under lock screen
 /// </summary>
 public void AquireWifiLock()
 {
     if (wifiLock == null)
     {
         wifiLock = wifiManager.CreateWifiLock(WifiMode.Full, "xamarin_wifi_lock");
     }
     wifiLock.Acquire();
 }
        /// <summary>
        /// This will release the wifi lock if it is no longer needed
        /// </summary>
        private void ReleaseWifiLock()
        {
            if (wifiLock == null)
                return;

            wifiLock.Release();
            wifiLock = null;
        }
Exemplo n.º 7
0
        public void InitMusicPlayer()
        {
            _appSettingsHelper = new AppSettingsHelper();
            _player = new MediaPlayer();
            _wifiLock = ((WifiManager)GetSystemService(WifiService)).CreateWifiLock(WifiMode.Full, "playerLock");

            _player.SetWakeMode(ApplicationContext, WakeLockFlags.Partial);
            _player.SetAudioStreamType(Stream.Music);
            _player.SetOnPreparedListener(this);
            _player.SetOnCompletionListener(this);
            _player.SetOnErrorListener(this);

            _audioManager = (AudioManager) GetSystemService(AudioService);

            _mediaButtonReceiverComponent = new ComponentName(ApplicationContext,
                Class.FromType(typeof (HeadsetButtonsReceiver)));
            _audioManager.RegisterMediaButtonEventReceiver(_mediaButtonReceiverComponent);
        }
Exemplo n.º 8
0
 protected override void OnStart()
 {
     base.OnStart();
     // Keep screen and wifi awake
     var powerManager = (PowerManager)GetSystemService(PowerService);
     var wifiManager = (WifiManager)GetSystemService(WifiService);
     _wakeLock = powerManager.NewWakeLock(WakeLockFlags.Full, "no sleep");
     _wakeLock.Acquire();
     _wifiLock = wifiManager.CreateWifiLock(WifiMode.FullHighPerf, "wifi on");
     _wifiLock.Acquire();
 }
 /// <summary>
 /// Lock the wifi so we can still stream under lock screen
 /// </summary>
 private void AquireWifiLock()
 {
     if (wifiLock == null)
     {
         wifiLock = wifiManager.CreateWifiLock(WifiMode.Full, "kvmr_wifi_lock");
     }
     wifiLock.Acquire();
 }