void StopLiveSession() { m_logger.Debug("StopLiveSession: EnableBackgroundAudio={0} IsInBackground={1}", EnableBackgroundAudio, IsInBackground); #if IOS_NATIVE if (EnableBackgroundAudio && Application.isMobilePlatform) { m_currentCategory = DefaultAudioCategory; IOSAudioSession.Instance.SetCategory(m_currentCategory, m_categoryOptions); } #endif if (ScreenSleepBehavior == ScreenSleepBehavior.OnDuringLiveSessions) { ThreadHelper.Instance.CallOnMainThread(() => { Screen.sleepTimeout = SleepTimeout.SystemSetting; }); } if (IsInBackground) { UserLocationService.Instance.Disable(); if (AudioContentPlayer.Instance) { AudioContentPlayer.Instance.Pause(); } } }
void StartLiveSession() { m_logger.Debug("StartLiveSession: EnableBackgroundAudio={0}", EnableBackgroundAudio); #if IOS_NATIVE if (Application.isMobilePlatform && EnableBackgroundAudio) { m_currentCategory = IOSAudioSessionCategory.Playback; IOSAudioSession.Instance.SetCategory(m_currentCategory, m_categoryOptions); } #endif if (ScreenSleepBehavior == ScreenSleepBehavior.OnDuringLiveSessions) { ThreadHelper.Instance.CallOnMainThread(() => { Screen.sleepTimeout = SleepTimeout.NeverSleep; }); } }
public void Initialize() { m_liveSessionListeners = new HashSet <object>(); IStepTracker stepTracker = null; #if IOS_NATIVE if (Application.isMobilePlatform) { m_logger.Debug("Initializing iOS Native"); m_categoryOptions = IOSAudioSessionCategoryOptions.None; if (MixWithOthers) { m_categoryOptions = IOSAudioSessionCategoryOptions.MixWithOthers; } m_currentCategory = DefaultAudioCategory; if (EnableBackgroundAudio) { IOSAudioSession.Instance.SetCategory(m_currentCategory, m_categoryOptions); IOSAudioSession.Instance.RemoteCommandReceived += (sender, args) => { if (args.Command == IOSAudioRemoteCommand.Pause) { SuspendLiveSession(); } }; } if (UseNativeDownloader) { FileDownloader.SetFactory(new IOSFileDownloaderFactory()); } AppDataPath = IOSFileDownloader.AppDataPath; Accelerometer = IOSMotionManager.Instance.GetAccelerometer(); LocationManager = IOSLocationManager.Instance; SystemCompass = new IOSCompass(); if (EnableBeacons) { BeaconManager = IOSBeaconManager.Instance; } if (EnableNotifications) { LocalNotificationManager = new IOSLocalNotificationManager(IOSLocalNotificationTypes.Badge | IOSLocalNotificationTypes.Sound); } } #endif #if ANDROID_NATIVE if (Application.isMobilePlatform) { m_logger.Debug("Initializing Android Native"); JavaClass activityClass = new JavaClass("com.unity3d.player.UnityPlayer"); JavaObject mainActivity = activityClass.GetStaticFieldValue <JavaObject>("currentActivity", "android.app.Activity"); AndroidApplicationManager.Instance.Initialize(mainActivity); LocationManager = new AndroidLocationManager(); if (EnableBeacons) { BeaconManager = new AndroidBeaconManager(); } if (EnableNotifications) { LocalNotificationManager = new AndroidLocalNotificationManager(StorageManager.GetFilePath("platform", "androidNotificationManager.json")); } } #endif if (BeaconManager == null && EnableBeacons) { BeaconManager = UnityBeaconManager.Instance; } if (Accelerometer == null) { Accelerometer = gameObject.AddComponent <UnityAccelerometer>(); } if (LocationManager == null) { LocationManager = gameObject.AddComponent <UnityLocationManager>(); } LocationManager.EnableBackgroundUpdates = EnableBackgroundLocation; if (SystemCompass == null) { SystemCompass = gameObject.AddComponent <UnityCompass>(); } if (LocalNotificationManager == null) { LocalNotificationManager = new DummyLocalNotificationManager(); } if (EnableNotifications && EnableBackgroundNotifications) { BackgroundNotifier.Instance.Initialize(); } var nrCompass = new NoiseDampeningCompass(SystemCompass); #if UNITY_ANDROID // Android compass tends to be much more jittery--apply a higher dampening // factor nrCompass.DampeningFactor = 0.25; #endif NoiseReducedCompass = nrCompass; if (Application.isMobilePlatform) { var accTracker = new AccelerometerStepTracker(Accelerometer); stepTracker = accTracker; Accelerometer.Start(); accTracker.Start(); } else { stepTracker = gameObject.AddComponent <DebugStepTracker>(); } Pedometer = new Pedometer(stepTracker); m_logger.Debug("Setting compass type={0}", CompassType); switch (CompassType) { case CompassType.System: Compass = SystemCompass; break; case CompassType.NoiseReduced: Compass = NoiseReducedCompass; break; case CompassType.LocationTracker: LocationTrackerCompass = new Motive.AR.LocationServices.LocationTrackerCompass(); Compass = LocationTrackerCompass; break; case CompassType.Hybrid: default: var hybrid = new HybridCompass(NoiseReducedCompass); LocationTrackerCompass = hybrid.TrackerCompass; Compass = hybrid; break; } AudioChannel = CreateAudioPlayerChannel(); ForegroundAudioChannel = gameObject.AddComponent <UnityAudioPlayerChannel>(); Pedometer.Stepped += (sender, args) => { if (ScriptEngine.Instance.UserInteractionEventManager != null) { ScriptEngine.Instance.UserInteractionEventManager.AddEvent("step"); } }; if (ScreenSleepBehavior == ScreenSleepBehavior.AlwaysOn) { Screen.sleepTimeout = SleepTimeout.NeverSleep; } }