示例#1
0
 static void Main(string[] args)
 {
     RemoteControlClient client = new RemoteControlClient("TCP");
     client.Do(new RemoteCommand() { CommandString = "Stop TV" });
     client.Do(new RemoteCommand() { CommandString = "Start TV" });
     Console.WriteLine(client.CountPendingCommands());
 }
示例#2
0
        /// <summary>
        /// Updates the state of the player.
        /// </summary>
        /// <param name="state">The state.</param>
        /// <param name="position"></param>
        public void UpdatePlaybackState(int state, int position = 0)
        {
            if (CurrentSession == null && (_binder?.IsBinderAlive).GetValueOrDefault(false) && !string.IsNullOrWhiteSpace(_packageName))
            {
                InitMediaSession(_packageName, _binder);
            }

            PlaybackStateCompat.Builder stateBuilder = new PlaybackStateCompat.Builder()
                                                       .SetActions(PlaybackStateCompat.ActionPlay
                                                                   | PlaybackStateCompat.ActionPlayPause
                                                                   | PlaybackStateCompat.ActionPause
                                                                   | PlaybackStateCompat.ActionSkipToNext
                                                                   | PlaybackStateCompat.ActionSkipToPrevious
                                                                   | PlaybackStateCompat.ActionStop);

            stateBuilder.SetState(state, position, 0, SystemClock.ElapsedRealtime());
            CurrentSession?.SetPlaybackState(stateBuilder.Build());
            OnStatusChanged?.Invoke(CurrentSession, state);

            //Used for backwards compatibility
            if ((Build.VERSION.SdkInt >= BuildVersionCodes.Lollipop) &&
                (CurrentSession?.RemoteControlClient == null ||
                 (bool)!CurrentSession?.RemoteControlClient.Equals(typeof(RemoteControlClient))))
            {
                return;
            }

            RemoteControlClient remoteControlClient = (RemoteControlClient)CurrentSession?.RemoteControlClient;

            RemoteControlFlags flags = RemoteControlFlags.Play
                                       | RemoteControlFlags.Pause
                                       | RemoteControlFlags.PlayPause;

            remoteControlClient?.SetTransportControlFlags(flags);
        }
示例#3
0
        public void RetArrayStructMethod()
        {
            RemoteControlClient cl = new RemoteControlClient(_port, RemoteControlServer.protectionKey);
            object ret             = cl.SendRequest("RetArrayStructMethod", new object[] { "i", 1, "s", "qwerty", "b", true });

            Assert.IsNotNull(ret as ArrayList);
            ArrayList a = ret as ArrayList;
            Hashtable h;

            TestStruct[] ras = properDelegateRetArrayStruct(1, "qwerty", true);

            Assert.IsNotNull(a[0] as Hashtable);
            h = a[0] as Hashtable;
            Assert.IsTrue(h.ContainsKey("i"));
            Assert.AreEqual(ras[0].i, (int)h["i"]);
            Assert.IsTrue(h.ContainsKey("s"));
            Assert.AreEqual(ras[0].s, (string)h["s"]);
            Assert.IsTrue(h.ContainsKey("b"));
            Assert.AreEqual(ras[0].b, (bool)h["b"]);

            Assert.IsNotNull(a[1] as Hashtable);
            h = a[1] as Hashtable;
            Assert.IsTrue(h.ContainsKey("i"));
            Assert.AreEqual(ras[1].i, (int)h["i"]);
            Assert.IsTrue(h.ContainsKey("s"));
            Assert.AreEqual(ras[1].s, (string)h["s"]);
            Assert.IsTrue(h.ContainsKey("b"));
            Assert.AreEqual(ras[1].b, (bool)h["b"]);
        }
示例#4
0
        /// <summary>
        /// Will register for the remote control client commands in audio manager
        /// </summary>
        private void RegisterRemoteClient()
        {
            try
            {
                if (remoteControlClient == null)
                {
                    audioManager.RegisterMediaButtonEventReceiver(remoteComponentName);
                    //Create a new pending intent that we want triggered by remote control client
                    var mediaButtonIntent = new Intent(Intent.ActionMediaButton);
                    mediaButtonIntent.SetComponent(remoteComponentName);
                    // Create new pending intent for the intent
                    var mediaPendingIntent = PendingIntent.GetBroadcast(this, 0, mediaButtonIntent, 0);
                    // Create and register the remote control client
                    remoteControlClient = new RemoteControlClient(mediaPendingIntent);
                    audioManager.RegisterRemoteControlClient(remoteControlClient);
                }


                //add transport control flags we can to handle
                remoteControlClient.SetTransportControlFlags(RemoteControlFlags.Play |
                                                             RemoteControlFlags.Pause);
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex);
            }
        }
示例#5
0
        protected override void OnCreate(Bundle savedInstanceState)
        {
            base.OnCreate(savedInstanceState);

            GoogleAnalyticsService.Instance.Initialize(this);
            GoogleAnalyticsService.Instance.TrackAppEvent(GoogleAnalyticsService.GAEventCategory.EnteringApp, "Entered splash screen");

            StartService(new Intent(this, typeof(ClosingService)));

            AudioManager  audioManager  = (AudioManager)this.GetSystemService(AudioService);
            ComponentName componentName = new ComponentName(this.PackageName, new BluetoothRemoteControlReciever().ComponentName);

            audioManager.RegisterMediaButtonEventReceiver(componentName);
            // build the PendingIntent for the remote control client
            Intent mediaButtonIntent = new Intent(Intent.ActionMediaButton);

            mediaButtonIntent.SetComponent(componentName);
            PendingIntent mediaPendingIntent = PendingIntent.GetBroadcast(ApplicationContext, 0, mediaButtonIntent, 0);
            // create and register the remote control client
            RemoteControlClient remoteControlClient = new RemoteControlClient(mediaPendingIntent);

            audioManager.RegisterRemoteControlClient(remoteControlClient);

            checkReadWriteToStorage();

            Task.Run(() =>
            {
                checkForUpdateVersionAsync();
            });
        }
示例#6
0
        public void IntegralMethod()
        {
            RemoteControlClient cl = new RemoteControlClient(_port, RemoteControlServer.protectionKey);
            object ret             = cl.SendRequest("IntegralMethod", new object[] { "i", 1, "s", "qwerty", "b", true });

            Assert.IsNotNull(ret as string);
            Assert.AreEqual(properDelegateIntegral(1, "qwerty", true), ret as string);
        }
示例#7
0
 /// <summary>
 /// Unregisters the remote client from the audio manger
 /// </summary>
 private void UnregisterRemoteClient()
 {
     try{
         audioManager.UnregisterMediaButtonEventReceiver(remoteComponentName);
         audioManager.UnregisterRemoteControlClient(remoteControlClient);
         remoteControlClient.Dispose();
         remoteControlClient = null;
     }catch (Exception ex) {
         Console.WriteLine(ex);
     }
 }
        private void UpdatePlaybackState(int state)
        {
            if (mediaSessionCompat == null || mediaPlayer == null)
            {
                return;
            }

            try
            {
                PlaybackStateCompat.Builder stateBuilder = new PlaybackStateCompat.Builder()
                                                           .SetActions(
                    PlaybackStateCompat.ActionPause |
                    PlaybackStateCompat.ActionPlay |
                    PlaybackStateCompat.ActionPlayPause |
                    PlaybackStateCompat.ActionSkipToNext |
                    PlaybackStateCompat.ActionSkipToPrevious |
                    PlaybackStateCompat.ActionStop
                    )
                                                           .SetState(state, Position, 1.0f, SystemClock.ElapsedRealtime());

                mediaSessionCompat.SetPlaybackState(stateBuilder.Build());

                //Used for backwards compatibility
                if (Build.VERSION.SdkInt < BuildVersionCodes.Lollipop)
                {
                    if (mediaSessionCompat.RemoteControlClient != null && mediaSessionCompat.RemoteControlClient.Equals(typeof(RemoteControlClient)))
                    {
                        RemoteControlClient remoteControlClient = (RemoteControlClient)mediaSessionCompat.RemoteControlClient;

                        RemoteControlFlags flags = RemoteControlFlags.Play
                                                   | RemoteControlFlags.Pause
                                                   | RemoteControlFlags.PlayPause
                                                   | RemoteControlFlags.Previous
                                                   | RemoteControlFlags.Next
                                                   | RemoteControlFlags.Stop;

                        remoteControlClient.SetTransportControlFlags(flags);
                    }
                }

                OnStatusChanged(EventArgs.Empty);

                if (state == PlaybackStateCompat.StatePlaying || state == PlaybackStateCompat.StatePaused)
                {
                    StartNotification();
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex);
            }
        }
示例#9
0
        public void StructMethod()
        {
            RemoteControlClient cl = new RemoteControlClient(_port, RemoteControlServer.protectionKey);
            TestStruct          s  = new TestStruct();

            s.i = 1;
            s.s = "qwery";
            s.b = true;
            object ret = cl.SendRequest("StructMethod", new object[] { "param", s });

            Assert.IsNotNull(ret as string);
            Assert.AreEqual(properDelegateStruct(s), ret as string);
        }
示例#10
0
 private void UnregisterRemoteClient()
 {
     try
     {
         this.audioManager.UnregisterMediaButtonEventReceiver(this.remoteComponentName);
         this.audioManager.UnregisterRemoteControlClient(this.remoteControlClient);
         if (this.remoteControlClient != null)
         {
             this.remoteControlClient.Dispose();
             this.remoteControlClient = null;
         }
     }
     catch (Exception)
     {
     }
 }
示例#11
0
        public void RetArrayMethod()
        {
            RemoteControlClient cl = new RemoteControlClient(_port, RemoteControlServer.protectionKey);
            object ret             = cl.SendRequest("RetArrayMethod", new object[] { "i", 1, "s", "qwerty", "b", true });

            string[] ra = properDelegateRetArray(1, "qwerty", true);

            Assert.IsNotNull(ret as ArrayList);
            ArrayList a = ret as ArrayList;

            Assert.IsNotNull(a[0] as string);
            Assert.AreEqual(ra[0], a[0] as string);
            Assert.IsNotNull(a[1] as string);
            Assert.AreEqual(ra[1], a[1] as string);
            Assert.IsNotNull(a[2] as string);
            Assert.AreEqual(ra[2], a[2] as string);
        }
示例#12
0
        public void RetStructMethod()
        {
            RemoteControlClient cl = new RemoteControlClient(_port, RemoteControlServer.protectionKey);
            TestStruct          s  = new TestStruct();
            object ret             = cl.SendRequest("RetStructMethod", new object[] { "i", 1, "s", "qwerty", "b", true });

            Assert.IsNotNull(ret as Hashtable);
            Hashtable h = ret as Hashtable;

            Assert.IsTrue(h.ContainsKey("i"));
            s.i = (int)h["i"];
            Assert.IsTrue(h.ContainsKey("s"));
            s.s = (string)h["s"];
            Assert.IsTrue(h.ContainsKey("b"));
            s.b = (bool)h["b"];
            Assert.AreEqual(properDelegateRetStruct(1, "qwerty", true), s);
        }
        public RemoteControlClientManager(Context mycontext)
        {
            var myEventReceiver = new ComponentName(mycontext.PackageName, nameof(RemoteControlReceiver));
            var myAudioManager  = (AudioManager)mycontext.GetSystemService(Context.AudioService);

            myAudioManager.RegisterMediaButtonEventReceiver(myEventReceiver);

            // build the PendingIntent for the remote control client
            Intent mediaButtonIntent = new Intent(Intent.ActionMediaButton);

            mediaButtonIntent.SetComponent(myEventReceiver);
            var mediaPendingIntent = PendingIntent.GetBroadcast(mycontext, 0, mediaButtonIntent, 0);

            // create and register the remote control client
            var myRemoteControlClient = new RemoteControlClient(mediaPendingIntent);

            myAudioManager.RegisterRemoteControlClient(myRemoteControlClient);
        }
示例#14
0
 private void RegisterRemoteClient()
 {
     this.remoteComponentName = new ComponentName(
         this.PackageName,
         new RemoteControlBroadcastReceiver().ComponentName);
     if (this.remoteControlClient == null)
     {
         this.audioManager.RegisterMediaButtonEventReceiver(this.remoteComponentName);
         //Create a new pending intent that we want triggered by remote control client
         var mediaButtonIntent = new Intent(Intent.ActionMediaButton);
         mediaButtonIntent.SetComponent(this.remoteComponentName);
         // Create new pending intent for the intent
         var mediaPendingIntent = PendingIntent.GetBroadcast(this, 0, mediaButtonIntent, 0);
         // Create and register the remote control client
         this.remoteControlClient = new RemoteControlClient(mediaPendingIntent);
         this.audioManager.RegisterRemoteControlClient(this.remoteControlClient);
     }
     //add transport control flags we can to handle
     this.remoteControlClient.SetTransportControlFlags(
         RemoteControlFlags.Play | RemoteControlFlags.Pause | RemoteControlFlags.PlayPause
         | RemoteControlFlags.Stop | RemoteControlFlags.Previous | RemoteControlFlags.Next);
 }
示例#15
0
 private FileDownloader(RemoteControlClient client)
 => _client = client;