Ejemplo n.º 1
0
 /**
  * Either stop casting or open the list of detected cast devices.
  */
 public void OnCastButtonTapped()
 {
     HideAll();
     darkMask.SetActive(true);
     if (isCasting)
     {
         CastDevice selectedDevice = CastRemoteDisplayManager.GetInstance().GetSelectedCastDevice();
         if (selectedDevice != null)
         {
             castDisconnectDialog.SetDeviceName(selectedDevice.DeviceName);
         }
         castDisconnectDialog.gameObject.SetActive(true);
     }
     else
     {
         CastError error = CastRemoteDisplayManager.GetInstance().GetLastError();
         if (error == null)
         {
             darkMask.SetActive(true);
             castListDialog.Show();
         }
         else
         {
             errorDialog.SetError(error);
             errorDialog.gameObject.SetActive(true);
         }
     }
 }
Ejemplo n.º 2
0
        /**
         * Returns devices available to start a remote display session with. Assumes #StartScan was
         * called.
         */
        public static List <CastDevice> GetCastDevices(ref CastDevice connectedCastDevice)
        {
            // Retrieve string array pointer, copy to C# managed string array, and then free pointer.
            IntPtr deviceInfoStringArrayPtr = _native_GCKUnityGetCastDeviceInfoAsStringArrayPtr();

            string[] deviceInfoStrings = getStringArrayFromNativePointer(deviceInfoStringArrayPtr);
            _native_GCKUnityFreeStringArrayPtr(deviceInfoStringArrayPtr);

            // The static library will respond with triplets of strings representing a cast device. The
            // order is deviceId, deviceName, and the status.
            List <CastDevice> devices = new List <CastDevice>();
            int i = 0;

            while (i < deviceInfoStrings.Length - 2)
            {
                // Creates a CastDevice with ID, Name, and Status.
                CastDevice device = new CastDevice(deviceInfoStrings[i++],
                                                   deviceInfoStrings[i++],
                                                   deviceInfoStrings[i++]);
                devices.Add(device);
                if (connectedCastDevice != null &&
                    connectedCastDevice.DeviceId == device.DeviceId)
                {
                    connectedCastDevice = device;
                }
            }
            return(devices);
        }
Ejemplo n.º 3
0
        void OnRouteUnselected(MediaRouter router, MediaRouter.RouteInfo route)
        {
            Console.WriteLine("OnRouteUnselected");

            Teardown(false);

            _selectedDevice = null;
        }
Ejemplo n.º 4
0
        void OnRouteSelected(MediaRouter router, MediaRouter.RouteInfo route)
        {
            Console.WriteLine("OnRouteSelected");

            _selectedDevice = CastDevice.GetFromBundle(route.Extras);

            LaunchReceiver();
        }
Ejemplo n.º 5
0
 private void TryConnectCast()
 {
     if (castDevices.Count > 0 && !castDisplayManager.IsCasting())
     {
         CastDevice device = castDevices[0];
         castDisplayManager.SelectCastDevice(device.DeviceId);
     }
 }
 public List<CastDevice> GetCastDevices(ref CastDevice connectedCastDevice) {
   foreach (CastDevice castDevice in displaySimulator.castDevices) {
     if (connectedCastDevice != null &&
         castDevice.DeviceId == connectedCastDevice.DeviceId) {
       connectedCastDevice = castDevice;
     }
   }
   return new List<CastDevice>(displaySimulator.castDevices);
 }
Ejemplo n.º 7
0
        public void OnMessageReceived(CastDevice castDevice, string nameSpace, string message)
        {
            var messageReceived = MessageReceived;

            if (messageReceived != null)
            {
                messageReceived(castDevice, nameSpace, message);
            }
        }
Ejemplo n.º 8
0
 /**
  * Stops the current remote display session. This can be used in the middle of the game to let
  * the user stop and disconnect and later select another Cast device.
  */
 public void StopRemoteDisplaySession()
 {
     DiscardGeneratedTextureIfNeeded();
     connectedCastDevice = null;
     isCasting           = false;
     if (castRemoteDisplayExtension != null)
     {
         castRemoteDisplayExtension.StopRemoteDisplaySession();
     }
 }
        public List <CastDevice> GetCastDevices(ref CastDevice connectedCastDevice)
        {
            List <CastDevice> devices = new List <CastDevice>();

            using (AndroidJavaClass bridge = new AndroidJavaClass(ANDROID_BRIDGE_CLASS_NAME)) {
                string statusString     = DEVICE_LIST_MARKER_NOT_DONE;
                int    numberOfJniCalls = 0;

                // The static library will respond with a partial device list.
                // The first string indicates whether the list is complete or not, after that, each
                // device is represented by 3 strings: The order is deviceId, deviceName and status.
                // We must call the method mutiple time to get the entire list.
                while (statusString != DEVICE_LIST_MARKER_DONE)
                {
                    using (AndroidJavaObject returnedArray =
                               bridge.CallStatic <AndroidJavaObject>(NATIVE_GET_CAST_DEVICES)) {
                        if (returnedArray != null && returnedArray.GetRawObject().ToInt32() != 0)
                        {
                            string[] deviceInfoStrings =
                                AndroidJNIHelper.ConvertFromJNIArray <string[]>(returnedArray.GetRawObject());
                            statusString = deviceInfoStrings[0];
                            int i = 1;
                            while (i < deviceInfoStrings.Length - 2)
                            {
                                // Creates a CastDevice with ID, Name, and Status.
                                CastDevice device = new CastDevice(deviceInfoStrings[i++],
                                                                   deviceInfoStrings[i++],
                                                                   deviceInfoStrings[i++]);
                                devices.Add(device);
                                if (connectedCastDevice != null &&
                                    connectedCastDevice.DeviceId == device.DeviceId)
                                {
                                    connectedCastDevice = device;
                                }
                            }
                        }
                        else
                        {
                            Debug.LogError("Couldn't retrieve list of Cast Devices.");
                            StopRemoteDisplaySession();
                            devices.Clear();
                            return(devices);
                        }
                    }
                    numberOfJniCalls++;
                    if (numberOfJniCalls >= MAX_NUMBER_OF_JNI_CALLS_FOR_CAST_DEVICES)
                    {
                        Debug.LogError("Couldn't retrieve the full list of cast devices. JNI call limit " +
                                       "exceeded.");
                        break;
                    }
                }
            }
            return(devices);
        }
 /**
  * Caches the device that is being connected to, so we can track the device name and ID.
  */
 private void CacheSelectedDevice(string deviceId)
 {
     foreach (CastDevice listDevice in castDevices)
     {
         if (listDevice.DeviceId == deviceId)
         {
             selectedCastDevice = listDevice;
             return;
         }
     }
 }
 public List <CastDevice> GetCastDevices(ref CastDevice connectedCastDevice)
 {
     foreach (CastDevice castDevice in displaySimulator.castDevices)
     {
         if (connectedCastDevice != null &&
             castDevice.DeviceId == connectedCastDevice.DeviceId)
         {
             connectedCastDevice = castDevice;
         }
     }
     return(new List <CastDevice>(displaySimulator.castDevices));
 }
Ejemplo n.º 12
0
        public void OnMessageReceived(CastDevice castDevice, string ns, string message)
        {
            Console.WriteLine("Message Received: {0} => {1}", ns, message);

            if (mediaPlayer != null && mediaPlayer.MediaStatus != null)
            {
                Console.WriteLine("MediaStatus available");
            }
            else
            {
                Console.WriteLine("MediaPlayer or MediaStatus is null");
            }
        }
Ejemplo n.º 13
0
        /**
         * Terminates the current remote display session (if any) and stops discovery on the native
         * extension.
         */
        private void Deactivate()
        {
            Debug.Log("Deactivating Cast Remote Display.");
            connectedCastDevice = null;
            isCasting           = false;
            StopRemoteDisplaySession();
            DiscardGeneratedTextureIfNeeded();

            if (castRemoteDisplayExtension != null)
            {
                castRemoteDisplayExtension.Deactivate();
            }
            castRemoteDisplayExtension = null;
            StopAllCoroutines();
            castDevices.Clear();
        }
Ejemplo n.º 14
0
    public string debugInfo()
    {
        string msg = "";

        dv = displayManager.GetSelectedCastDevice();
        Debug.Log("displayManager.enabled: " + displayManager.enabled);
        if (dv != null)
        {
            msg = (" DeviceId: " + dv.DeviceId + " DeviceName: " + dv.DeviceName + " Status:" + dv.Status + " displayManager.IsCasting: " + displayManager.IsCasting());
        }
        else
        {
            msg = (" chromecast null");
        }
        return(msg);
    }
Ejemplo n.º 15
0
        void Teardown(bool selectDefaultRoute)
        {
            Console.WriteLine("Teardown");

            if (_apiClient != null)
            {
                if (_applicationStarted)
                {
                    _applicationStarted = false;
                    _hasJoined          = false;
                    if (_apiClient.IsConnected || _apiClient.IsConnecting)
                    {
                        try
                        {
                            CastClass.CastApi.LeaveApplication(_apiClient);
                            if (_channel != null)
                            {
                                CastClass.CastApi.RemoveMessageReceivedCallbacks(
                                    _apiClient,
                                    MyChannel.CastNamespace);
                                _channel = null;
                            }
                        }
                        catch (Exception e)
                        {
                            Console.WriteLine("Exception while removing channel - {0}", e);
                        }
                        _apiClient.Disconnect();
                    }
                }
                _apiClient = null;
            }

            if (selectDefaultRoute)
            {
                _mediaRouter.SelectRoute(_mediaRouter.DefaultRoute);
            }
            _selectedDevice = null;

            _textGuess.Text = string.Empty;
            UpdateEnabledStates();
        }
Ejemplo n.º 16
0
        void Init()
        {
            mediaRouter = MediaRouter.GetInstance(this);

            mediaRouteSelector =
                new MediaRouteSelector.Builder().AddControlCategory(MediaControlIntent.CategoryRemotePlayback)   //CastMediaControlIntent.CategoryForCast (APP_ID))
                .Build();
            mediaRouteButton.RouteSelector = mediaRouteSelector;

            myMediaRouterCallback = new MyMediaRouterCallback {
                OnRouteSelectedHandler = (router, route) => {
                    Console.WriteLine("Route Selected: " + route.Name);

                    var device = CastDevice.GetFromBundle(route.Extras);

                    myCastListener = new MyCastListener();

                    var apiOptionsBuilder = new CastClass.CastOptions.Builder(
                        device,
                        myCastListener).SetVerboseLoggingEnabled(true);

                    googleApiClient = new GoogleApiClientBuilder(this)
                                      .AddApi(CastClass.API, apiOptionsBuilder.Build())
                                      .AddConnectionCallbacks(this)
                                      .AddOnConnectionFailedListener(this)
                                      .Build();

                    googleApiClient.Connect();
                },
                OnRouteUnselectedHandler = (router, route) => {
                    Console.WriteLine("Route Unselected: " + route.Name);
                },
                RouteCountChangedHandler = newCount => {
                    mediaRouteButton.Visibility = newCount > 0 ? ViewStates.Visible : ViewStates.Gone;
                }
            };

            mediaRouter.AddCallback(mediaRouteSelector, myMediaRouterCallback, MediaRouter.CallbackFlagRequestDiscovery);
        }
        /**
         * Returns devices available to start a remote display session with. Assumes #StartScan was
         * called.
         */
        public static List<CastDevice> GetCastDevices(ref CastDevice connectedCastDevice)
        {
            // Retrieve string array pointer, copy to C# managed string array, and then free pointer.
              IntPtr deviceInfoStringArrayPtr = _native_GCKUnityGetCastDeviceInfoAsStringArrayPtr();
              string[] deviceInfoStrings = getStringArrayFromNativePointer(deviceInfoStringArrayPtr);
              _native_GCKUnityFreeStringArrayPtr(deviceInfoStringArrayPtr);

              // The static library will respond with triplets of strings representing a cast device. The
              // order is deviceId, deviceName, and the status.
              List<CastDevice> devices = new List<CastDevice>();
              int i = 0;
              while (i < deviceInfoStrings.Length - 2) {
            // Creates a CastDevice with ID, Name, and Status.
            CastDevice device = new CastDevice(deviceInfoStrings[i++],
            deviceInfoStrings[i++],
            deviceInfoStrings[i++]);
            devices.Add(device);
            if (connectedCastDevice != null &&
            connectedCastDevice.DeviceId == device.DeviceId) {
              connectedCastDevice = device;
            }
              }
              return devices;
        }
Ejemplo n.º 18
0
		void Teardown(bool selectDefaultRoute)
		{
			Console.WriteLine ("Teardown");

			if (_apiClient != null)
			{
				if (_applicationStarted)
				{
					_applicationStarted = false;
					_hasJoined = false;
					if (_apiClient.IsConnected || _apiClient.IsConnecting)
					{
						try
						{
							CastClass.CastApi.LeaveApplication(_apiClient);
							if (_channel != null)
							{
								CastClass.CastApi.RemoveMessageReceivedCallbacks(
									_apiClient,
									MyChannel.CastNamespace);
								_channel = null;
							}
						}
						catch (Exception e)
						{
							Console.WriteLine("Exception while removing channel - {0}", e);
						}
						_apiClient.Disconnect();
					}
				}
				_apiClient = null;
			}

			if (selectDefaultRoute)
			{
				_mediaRouter.SelectRoute(_mediaRouter.DefaultRoute);
			}
			_selectedDevice = null;

			_textGuess.Text = string.Empty;
			UpdateEnabledStates ();
		}
Ejemplo n.º 19
0
		void OnMessageReceived(CastDevice castDevice, string nameSpace, string message)
		{
			Console.WriteLine ("OnMessageReceived: {0}", message);
		}
Ejemplo n.º 20
0
		void OnRouteSelected (MediaRouter router, MediaRouter.RouteInfo route)
		{
			Console.WriteLine ("OnRouteSelected");

			_selectedDevice = CastDevice.GetFromBundle (route.Extras);

			LaunchReceiver ();
		}
Ejemplo n.º 21
0
		void OnRouteUnselected (MediaRouter router, MediaRouter.RouteInfo route)
		{
			Console.WriteLine ("OnRouteUnselected");

			Teardown (false);

			_selectedDevice = null;
		}
 private void disconnect()
 {
     DiscardGeneratedTextureIfNeeded();
     selectedCastDevice = null;
     isCasting          = false;
 }
Ejemplo n.º 23
0
        public void OnMessageReceived (CastDevice castDevice, string ns, string message)
        {
            Console.WriteLine ("Message Received: {0} => {1}", ns, message);

            if (mediaPlayer != null && mediaPlayer.MediaStatus != null) {
                Console.WriteLine ("MediaStatus available");
            } else {
                Console.WriteLine ("MediaPlayer or MediaStatus is null");
            }
        }
 public List<CastDevice> GetCastDevices(ref CastDevice connectedCastDevice) {
   return CastRemoteDisplayiOSUnityBridge.GetCastDevices(ref connectedCastDevice);
 }
 /**
  * Stops the current remote display session. This can be used in the middle of the game to let
  * the user stop and disconnect and later select another Cast device.
  */
 public void StopRemoteDisplaySession() {
   DiscardGeneratedTextureIfNeeded();
   connectedCastDevice = null;
   isCasting = false;
   if (castRemoteDisplayExtension != null) {
     castRemoteDisplayExtension.StopRemoteDisplaySession();
   }
 }
Ejemplo n.º 26
0
 public void OnDeviceSelected(CastDevice p0)
 {
 }
Ejemplo n.º 27
0
 void OnMessageReceived(CastDevice castDevice, string nameSpace, string message)
 {
     Console.WriteLine("OnMessageReceived: {0}", message);
 }
 /**
  * Caches the device that is being connected to, so we can track the device name and ID.
  */
 private void CacheSelectedDevice(string deviceId)
 {
     foreach (CastDevice listDevice in castDevices) {
     if (listDevice.DeviceId == deviceId) {
       selectedCastDevice = listDevice;
       return;
     }
       }
 }
 public Task <Android.Views.Display> StartRemoteDisplayAsync(CastDevice castDevice, string applicationId, int configPreset, Android.App.PendingIntent sessionEndedPendingIntent)
 {
     return(StartRemoteDisplay(castDevice, applicationId, configPreset, sessionEndedPendingIntent).AsAsync <Android.Views.Display>());
 }
 private void disconnect()
 {
     DiscardGeneratedTextureIfNeeded();
       selectedCastDevice = null;
       isCasting = false;
 }
    /**
     * Terminates the current remote display session (if any) and stops discovery on the native
     * extension.
     */
    private void Deactivate() {
      Debug.Log("Deactivating Cast Remote Display.");
      connectedCastDevice = null;
      isCasting = false;
      StopRemoteDisplaySession();
      DiscardGeneratedTextureIfNeeded();

      if (castRemoteDisplayExtension != null) {
        castRemoteDisplayExtension.Deactivate();
      }
      castRemoteDisplayExtension = null;
      StopAllCoroutines();
      castDevices.Clear();
    }
Ejemplo n.º 32
0
		public void OnMessageReceived (CastDevice castDevice, string nameSpace, string message)
		{
			var messageReceived = MessageReceived;
			if (messageReceived != null)
				messageReceived (castDevice, nameSpace, message);
		}
        public List<CastDevice> GetCastDevices(ref CastDevice connectedCastDevice)
        {
            List<CastDevice> devices = new List<CastDevice>();
              using (AndroidJavaClass bridge = new AndroidJavaClass(ANDROID_BRIDGE_CLASS_NAME)) {

            string statusString = DEVICE_LIST_MARKER_NOT_DONE;
            int numberOfJniCalls = 0;

            // The static library will respond with a partial device list.
            // The first string indicates whether the list is complete or not, after that, each
            // device is represented by 3 strings: The order is deviceId, deviceName and status.
            // We must call the method mutiple time to get the entire list.
            while (statusString != DEVICE_LIST_MARKER_DONE) {
              using (AndroidJavaObject returnedArray =
              bridge.CallStatic<AndroidJavaObject>(NATIVE_GET_CAST_DEVICES)) {
            if (returnedArray != null && returnedArray.GetRawObject().ToInt32() != 0) {
              string[] deviceInfoStrings =
                  AndroidJNIHelper.ConvertFromJNIArray<string[]>(returnedArray.GetRawObject());
              statusString = deviceInfoStrings[0];
              int i = 1;
              while (i < deviceInfoStrings.Length - 2) {
                // Creates a CastDevice with ID, Name, and Status.
                CastDevice device = new CastDevice(deviceInfoStrings[i++],
                    deviceInfoStrings[i++],
                    deviceInfoStrings[i++]);
                devices.Add(device);
                if (connectedCastDevice != null &&
                    connectedCastDevice.DeviceId == device.DeviceId) {
                  connectedCastDevice = device;
                }
              }
            } else {
              Debug.LogError("Couldn't retrieve list of Cast Devices.");
              StopRemoteDisplaySession();
              devices.Clear();
              return devices;
            }
              }
              numberOfJniCalls++;
              if (numberOfJniCalls >= MAX_NUMBER_OF_JNI_CALLS_FOR_CAST_DEVICES) {
            Debug.LogError("Couldn't retrieve the full list of cast devices. JNI call limit " +
                "exceeded.");
            break;
              }
            }
              }
              return devices;
        }
Ejemplo n.º 34
0
 public override void OnRouteSelected(MediaRouter router, MediaRouter.RouteInfo route)
 {
     //base.OnRouteSelected(router, route);
     castDevice = CastDevice.GetFromBundle(route.Extras);
     System.Diagnostics.Debug.WriteLine("SELECTED; Connected to: " + route.Name);
 }
Ejemplo n.º 35
0
 public override void OnRouteUnselected(MediaRouter router, MediaRouter.RouteInfo route)
 {
     //base.OnRouteUnselected(router, route);
     System.Diagnostics.Debug.WriteLine("UNSELECTED");
     castDevice = null;
 }
 public List <CastDevice> GetCastDevices(ref CastDevice connectedCastDevice)
 {
     return(CastRemoteDisplayiOSUnityBridge.GetCastDevices(ref connectedCastDevice));
 }