Esempio n. 1
0
        /// <summary>
        /// When we start on the foreground we will present a notification to the user
        /// When they press the notification it will take them to the main page so they can control the music
        /// </summary>
        public void StartNotification(IMediaFile mediaFile, bool mediaIsPlaying, bool canBeRemoved)
        {
            var icon = (_appliactionContext.Resources?.GetIdentifier("xam_mediamanager_notify_ic", "drawable", _appliactionContext?.PackageName)).GetValueOrDefault(0);

            _notificationStyle.SetMediaSession(_sessionToken);
            _notificationStyle.SetCancelButtonIntent(_pendingCancelIntent);

            _builder = new NotificationCompat.Builder(_appliactionContext)
            {
                MStyle = _notificationStyle
            };
            _builder.SetSmallIcon(icon != 0 ? icon : _appliactionContext.ApplicationInfo.Icon);
            _builder.SetContentIntent(_pendingIntent);
            _builder.SetOngoing(mediaIsPlaying);
            _builder.SetVisibility(1);

            SetMetadata(mediaFile);
            AddActionButtons(mediaIsPlaying);
            if (_builder.MActions.Count >= 3)
            {
                ((NotificationCompat.MediaStyle)(_builder.MStyle)).SetShowActionsInCompactView(0, 1, 2);
            }

            NotificationManagerCompat.From(_appliactionContext)
            .Notify(MediaServiceBase.NotificationId, _builder.Build());
        }
        public void UpdateNotifications(IMediaFile mediaFile, MediaPlayerStatus status)
        {
            try
            {
                var isPlaying    = status == MediaPlayerStatus.Playing || status == MediaPlayerStatus.Buffering;
                var isPersistent = status == MediaPlayerStatus.Playing || status == MediaPlayerStatus.Buffering || status == MediaPlayerStatus.Paused;
                var nm           = NotificationManagerCompat.From(_applicationContext);
                if (nm != null && _builder != null)
                {
                    SetMetadata(mediaFile);
                    AddActionButtons(isPlaying);
                    _builder.SetOngoing(isPersistent);

                    var notification = _builder.Build();
                    CheckSmallIconInMIUI(notification);

                    nm.Notify(_notificationId, notification);
                }
                else
                {
                    StartNotification(mediaFile, isPlaying, false);
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
                StopNotifications();
            }
        }
        /// <summary>
        /// When we start on the foreground we will present a notification to the user
        /// When they press the notification it will take them to the main page so they can control the music
        /// </summary>
        public void StartNotification(IMediaFile mediaFile, bool mediaIsPlaying, bool canBeRemoved)
        {
            _notificationStyle.SetMediaSession(_sessionToken);
            _notificationStyle.SetCancelButtonIntent(_pendingCancelIntent);
            _notificationStyle.SetShowActionsInCompactView(0, 1, 2);

            _builder = new NotificationCompat.Builder(_appliactionContext)
            {
                MStyle = _notificationStyle
            };
            _builder.SetSmallIcon(_appliactionContext.ApplicationInfo.Icon);
            _builder.SetContentIntent(_pendingIntent);
            _builder.SetOngoing(true);
            _builder.SetVisibility(1);

            SetMetadata(mediaFile);
            AddActionButtons(mediaIsPlaying);

            NotificationManagerCompat.From(_appliactionContext)
                .Notify(MediaServiceBase.NotificationId, _builder.Build());
        }
Esempio n. 4
0
        /// <summary>
        /// When we start on the foreground we will present a notification to the user
        /// When they press the notification it will take them to the main page so they can control the music
        /// </summary>
        public void StartNotification(IMediaFile mediaFile, bool mediaIsPlaying, bool canBeRemoved)
        {
            _notificationStyle.SetMediaSession(_sessionToken);
            _notificationStyle.SetCancelButtonIntent(_pendingCancelIntent);
            _notificationStyle.SetShowActionsInCompactView(0, 1, 2);

            _builder = new NotificationCompat.Builder(_appliactionContext)
            {
                MStyle = _notificationStyle
            };
            _builder.SetSmallIcon(_appliactionContext.ApplicationInfo.Icon);
            _builder.SetContentIntent(_pendingIntent);
            _builder.SetOngoing(true);
            _builder.SetVisibility(1);

            SetMetadata(mediaFile);
            AddActionButtons(mediaIsPlaying);

            NotificationManagerCompat.From(_appliactionContext)
            .Notify(MediaServiceBase.NotificationId, _builder.Build());
        }
        /// <summary>
        /// When we start on the foreground we will present a notification to the user
        /// When they press the notification it will take them to the main page so they can control the music
        /// </summary>
        public void StartNotification(IMediaFile mediaFile, bool mediaIsPlaying, bool canBeRemoved)
        {
            var icon = (_appliactionContext.Resources?.GetIdentifier("xam_mediamanager_notify_ic", "drawable", _appliactionContext?.PackageName)).GetValueOrDefault(0);
           
            _notificationStyle.SetMediaSession(_sessionToken);
            _notificationStyle.SetCancelButtonIntent(_pendingCancelIntent);
            _notificationStyle.SetShowActionsInCompactView(0, 1, 2);

            _builder = new NotificationCompat.Builder(_appliactionContext)
            {
                MStyle = _notificationStyle
            };
            _builder.SetSmallIcon(icon != 0 ? icon : _appliactionContext.ApplicationInfo.Icon);
            _builder.SetContentIntent(_pendingIntent);
            _builder.SetOngoing(mediaIsPlaying);
            _builder.SetVisibility(1);

            SetMetadata(mediaFile);
            AddActionButtons(mediaIsPlaying);

            NotificationManagerCompat.From(_appliactionContext)
                .Notify(MediaServiceBase.NotificationId, _builder.Build());
        }
 public void UpdateNotifications(IMediaFile mediaFile, MediaPlayerStatus status)
 {
     try
     {
         var isPlaying = status == MediaPlayerStatus.Playing || status == MediaPlayerStatus.Buffering;
         var nm        = NotificationManagerCompat.From(_appliactionContext);
         if (nm != null && _builder != null)
         {
             SetMetadata(mediaFile);
             AddActionButtons(isPlaying);
             _builder.SetOngoing(isPlaying);
             nm.Notify(MediaServiceBase.NotificationId, _builder.Build());
         }
         else
         {
             StartNotification(mediaFile, isPlaying, false);
         }
     }
     catch (Exception ex)
     {
         Console.WriteLine(ex.Message);
         StopNotifications();
     }
 }