internal void InitMediaSession(string packageName, MediaServiceBinder binder) { try { if (mediaSessionCompat == null) { Intent nIntent = new Intent(applicationContext, typeof(MediaPlayer)); PendingIntent pIntent = PendingIntent.GetActivity(applicationContext, 0, nIntent, 0); RemoteComponentName = new ComponentName(packageName, new RemoteControlBroadcastReceiver().ComponentName); mediaSessionCompat = new MediaSessionCompat(applicationContext, "XamarinStreamingAudio", RemoteComponentName, pIntent); mediaControllerCompat = new MediaControllerCompat(applicationContext, mediaSessionCompat.SessionToken); } mediaSessionCompat.Active = true; //mediaSessionCompat.SetCallback(binder.GetMediaPlayerService().AlternateRemoteCallback ?? new MediaSessionCallback(binder)); mediaSessionCompat.SetFlags(MediaSessionCompat.FlagHandlesMediaButtons | MediaSessionCompat.FlagHandlesTransportControls); NotificationManager = new MediaNotificationManagerImplementation(applicationContext, CurrentSession.SessionToken, typeof(MediaPlayerService)); _packageName = packageName; _binder = binder; } catch (Exception ex) { Console.WriteLine(ex); } }
/// <summary> /// Will register for the remote control client commands in audio manager /// </summary> private void InitMediaSession() { try { if (mediaSessionCompat == null) { Intent nIntent = new Intent(this.ApplicationContext, typeof(MainActivity)); PendingIntent pIntent = PendingIntent.GetActivity(this.ApplicationContext, 0, nIntent, 0); remoteComponentName = new ComponentName(this.PackageName, new RemoteControlBroadcastReceiver().ComponentName); mediaSessionCompat = new MediaSessionCompat(this.ApplicationContext, "XamarinStreamingAudio", remoteComponentName, pIntent); mediaControllerCompat = new MediaControllerCompat(this.ApplicationContext, mediaSessionCompat.SessionToken); } mediaSessionCompat.Active = true; mediaSessionCompat.SetCallback(new MediaSessionCallback((MediaPlayerServiceBinder)binder)); mediaSessionCompat.SetFlags(MediaSessionCompat.FlagHandlesMediaButtons | MediaSessionCompat.FlagHandlesTransportControls); } catch (Exception ex) { Console.WriteLine(ex); } }
internal void InitMediaSession(string packageName, MediaServiceBinder binder) { try { if (mediaSessionCompat == null) { Intent nIntent = new Intent(applicationContext, typeof(MediaPlayer)); PendingIntent pIntent = PendingIntent.GetActivity(applicationContext, 0, nIntent, 0); RemoteComponentName = new ComponentName(packageName, new RemoteControlBroadcastReceiver().ComponentName); mediaSessionCompat = new MediaSessionCompat(applicationContext, "XamarinStreamingAudio", RemoteComponentName, pIntent); mediaControllerCompat = new MediaControllerCompat(applicationContext, mediaSessionCompat.SessionToken); NotificationManager = new MediaNotificationManagerImplementation(applicationContext, CurrentSession.SessionToken, _serviceType); } mediaSessionCompat.Active = true; mediaSessionCompat.SetCallback(binder.GetMediaPlayerService<MediaServiceBase>().AlternateRemoteCallback ?? new MediaSessionCallback(this)); mediaSessionCompat.SetFlags(MediaSessionCompat.FlagHandlesMediaButtons | MediaSessionCompat.FlagHandlesTransportControls); _packageName = packageName; _binder = binder; } catch (Exception ex) { Console.WriteLine(ex); } }
public RadioStationMediaSession(Context context) { var intent = new Intent(context, typeof(Android.App.Activity)); var pendingIntent = PendingIntent.GetActivity(context, 0, intent, 0); var componentName = new ComponentName(context.PackageName, new RadioStationBroadcastReceiver().ComponentName); _session = new MediaSessionCompat(context, "wzxv.app", componentName, pendingIntent); _controller = new MediaControllerCompat(context, _session.SessionToken); _session.SetCallback(new MediaSessionCallback(context)); _session.SetFlags(MediaSessionCompat.FlagHandlesMediaButtons | MediaSessionCompat.FlagHandlesTransportControls); _session.Active = true; }
private void ConnectToSession(MediaSessionCompat.Token token) { SupportMediaController = new MediaControllerCompat(this, token); if (ShouldShowControls) { ShowPlaybackControls(); } else { LogHelper.Debug(Tag, "connectionCallback.onConnected: " + "hiding controls because metadata is null"); HidePlaybackControls(); } OnConnected(); }
void ConnectToSession(MediaSessionCompat.Token token) { var controller = new MediaControllerCompat(this, token); this.SupportMediaController = controller; controller.RegisterCallback(callBack = new MediaControllerCallBack { Parent = this }); if (ShouldShowControls()) { ShowPlaybackControls(); } else { HidePlaybackControls(); } ControlsFragment?.OnConnected(); OnMediaControllConnected(); }
void UpdateSessionToken() { var freshToken = Service.SessionToken; if (freshToken == null || sessionToken == freshToken) { return; } controller?.UnregisterCallback(callback); sessionToken = freshToken; controller = new MediaControllerCompat(Service, sessionToken); transportControls = controller.GetTransportControls(); if (started) { controller.RegisterCallback(callback); } }
void UpdateSessionToken() { var freshToken = service.SessionToken; if (sessionToken == null && freshToken != null || sessionToken != null && sessionToken != freshToken) { controller?.UnregisterCallback(mCb); sessionToken = freshToken; if (sessionToken != null) { controller = new MediaControllerCompat(service, sessionToken); transportControls = controller.GetTransportControls(); if (started) { controller.RegisterCallback(mCb); } } } }
private void InitializeMediaSession() { try { if (_mediaSessionCompat == null) { Intent intent = new Intent(ApplicationContext, typeof(MainActivity)); PendingIntent pendingIntent = PendingIntent.GetActivity(ApplicationContext, 0, intent, 0); _remoteComponentName = new ComponentName(PackageName, new AudioControlsBroadcastReceiver().ComponentName); _mediaSessionCompat = new MediaSessionCompat(ApplicationContext, "VinylScratch", _remoteComponentName, pendingIntent); _mediaControllerCompat = new MediaControllerCompat(ApplicationContext, _mediaSessionCompat.SessionToken); } _mediaSessionCompat.Active = true; _mediaSessionCompat.SetCallback(new AudioServiceCallback((AudioServiceBinder)_binder)); _mediaSessionCompat.SetFlags(MediaSessionCompat.FlagHandlesMediaButtons | MediaSessionCompat.FlagHandlesTransportControls); } catch (Exception e) { System.Diagnostics.Debug.WriteLine(e); } }
public bool Init() { if (MediaBrowser == null) { MediaControllerCallback = new MediaControllerCallback(); MediaBrowserSubscriptionCallback = new MediaBrowserSubscriptionCallback(); // Connect a media browser just to get the media session token. There are other ways // this can be done, for example by sharing the session token directly. TaskCompletionSource <bool> tcs = new TaskCompletionSource <bool>(); MediaBrowserConnectionCallback = new MediaBrowserConnectionCallback { OnConnectedImpl = () => { MediaControllerCallback.OnMetadataChangedImpl = metadata => { var test = metadata; }; MediaControllerCallback.OnPlaybackStateChangedImpl = state => { MediaManager.OnStateChanged(this, new StateChangedEventArgs(state.ToMediaPlayerState())); }; MediaControllerCallback.OnSessionEventChangedImpl = (string @event, Bundle extras) => { //Do nothing for now }; MediaController = new MediaControllerCompat(Context, MediaBrowser.SessionToken); MediaController.RegisterCallback(MediaControllerCallback); if (Context is Activity activity) { MediaControllerCompat.SetMediaController(activity, MediaController); } // Sync existing MediaSession state to the UI. // The first time these events are fired, the metadata and playbackstate are null. MediaControllerCallback.OnMetadataChanged(MediaController.Metadata); MediaControllerCallback.OnPlaybackStateChanged(MediaController.PlaybackState); MediaBrowser.Subscribe(MediaBrowser.Root, MediaBrowserSubscriptionCallback); IsInitialized = true; tcs.SetResult(IsInitialized); }, OnConnectionFailedImpl = () => { IsInitialized = false; tcs.SetResult(IsInitialized); } }; MediaBrowser = new MediaBrowserCompat(Context, new ComponentName( Context, ServiceType), MediaBrowserConnectionCallback, null); } if (!IsInitialized) { MediaBrowser.Connect(); IsInitialized = true; } return(IsInitialized); }
/// <summary> /// Will register for the remote control client commands in audio manager /// </summary> private void InitMediaSession() { try { if (mediaSessionCompat == null) { Intent nIntent = new Intent(ApplicationContext, typeof(MainActivity)); PendingIntent pIntent = PendingIntent.GetActivity(ApplicationContext, 0, nIntent, 0); remoteComponentName = new ComponentName (PackageName, new RemoteControlBroadcastReceiver ().ComponentName); mediaSessionCompat = new MediaSessionCompat (ApplicationContext, "XamarinStreamingAudio", remoteComponentName, pIntent); mediaControllerCompat = new MediaControllerCompat(ApplicationContext, mediaSessionCompat.SessionToken); } mediaSessionCompat.Active = true; mediaSessionCompat.SetCallback (new MediaSessionCallback((MediaPlayerServiceBinder)binder)); mediaSessionCompat.SetFlags(MediaSessionCompat.FlagHandlesMediaButtons | MediaSessionCompat.FlagHandlesTransportControls); } catch (Exception ex) { Console.WriteLine (ex); } }