internal static List <NotificationChannel> ToNotificationChannels(this List <Android.App.NotificationChannel> channels)
        {
            List <NotificationChannel> result = new List <NotificationChannel>();

            foreach (var channel in channels)
            {
                NotificationChannel newChannel = new NotificationChannel();
                newChannel.LockscreenVisibility = channel.LockscreenVisibility.EnumToEnum <NotificationVisibility>();
                newChannel.LightColor           = channel.LightColor;
                newChannel.Importance           = channel.Importance.EnumToEnum <NotificationImportance>();
                newChannel.Id          = channel.Id;
                newChannel.Group       = channel.Group;
                newChannel.Description = channel.Description;
                if (channel.Sound != null)
                {
                    newChannel.Sound = new Uri(channel.Sound.ToString());
                }
                newChannel.Name          = channel.Name;
                newChannel.NameFormatted = channel.NameFormatted.ToString();

                if (channel.AudioAttributes != null)
                {
                    AudioAttributes newAudioAttributes = new AudioAttributes();
                    newAudioAttributes.ContentType         = channel.AudioAttributes.ContentType.EnumToEnum <AudioContentType>();
                    newAudioAttributes.Flags               = channel.AudioAttributes.Flags.EnumToEnum <AudioFlags>();
                    newAudioAttributes.Usage               = channel.AudioAttributes.Usage.EnumToEnum <AudioUsageKind>();
                    newAudioAttributes.VolumeControlStream = channel.AudioAttributes.VolumeControlStream.EnumToEnum <Stream>();
                    newChannel.AudioAttributes             = newAudioAttributes;
                }

                result.Add(newChannel);
            }

            return(result);
        }
Exemple #2
0
    public static float GetAttribute(AudioStream audioStream, AudioAttributes attribute)
    {
        float value = 0;

        Bass.BASS_ChannelGetAttribute(audioStream.audioHandle, (BASSAttribute)attribute, ref value);
        return(value);
    }
        private void IntializePlayer()
        {
            player = new MediaPlayer();

            mPlaybackAttributes = new AudioAttributes.Builder()
                                  .SetLegacyStreamType(Stream.Music)
                                  .SetUsage(AudioUsageKind.Media)
                                  .SetContentType(AudioContentType.Music)
                                  .Build();

            player.SetAudioAttributes(mPlaybackAttributes);

            player.SetWakeMode(ApplicationContext, WakeLockFlags.Partial);

            player.Prepared += (sender, args) => {
                player.Start();
                Console.WriteLine("start playback: " + MainActivity.AudioPath);
            };

            player.Completion += (sender, args) => Stop();

            player.Error += (sender, args) =>
            {
                Stop();
            };
        }
Exemple #4
0
        public SimplePhraseMessenger(TextToSpeech speechEngine, string phrase, int numRepeats)
        {
            this.speechEngine = speechEngine;
            this.phrase       = phrase;
            this.numRepeats   = numRepeats;
            AudioAttributes.Builder b = new AudioAttributes.Builder();
            b.SetFlags(AudioFlags.LowLatency);
            b.SetUsage(AudioUsageKind.Alarm);
            b.SetContentType(AudioContentType.Speech);

            AudioAttributes audioAttributes = b.Build();

            speechEngine.SetAudioAttributes(audioAttributes);
        }
Exemple #5
0
 public static void SetAttribute(AudioStream audioStream, AudioAttributes attribute, float value)
 {
     Bass.BASS_ChannelSetAttribute(audioStream.audioHandle, (BASSAttribute)attribute, value);
 }
        public AudioFocusManager(IMediaPlayer <SimpleExoPlayer> player)
        {
            this.mediaPlayer = player;
            context          = global::Android.App.Application.Context;
            mAudioManager    = (AudioManager)context.GetSystemService(Context.AudioService);

            mAudioAttributes = new AudioAttributes.Builder()
                               .SetUsage(AudioUsageKind.Media)
                               .SetContentType(AudioContentType.Music)
                               .Build();

            mFocusListener = new AudioFocusListener
            {
                OnAudioFocusChangeImpl = (focusChange) =>
                {
                    switch (focusChange)
                    {
                    case AudioFocus.Gain:
                        if (ShouldPlayWhenReady && !IsPlaying())
                        {
                            exoPlayer.PlayWhenReady = true;     //play.
                        }
                        else if (IsPlaying())
                        {
                            exoPlayer.Volume = MEDIA_VOLUME_DEFAULT;
                        }

                        ShouldPlayWhenReady = false;
                        break;

                    case AudioFocus.LossTransientCanDuck:
                        exoPlayer.Volume = MEDIA_VOLUME_DUCK;
                        break;

                    case AudioFocus.LossTransient:
                        if (IsPlaying())
                        {
                            ShouldPlayWhenReady = true;

                            exoPlayer.PlayWhenReady = false;     //pause.
                        }
                        break;

                    case AudioFocus.Loss:
                        AbandonAudioFocus();
                        ShouldPlayWhenReady = false;
                        break;
                    }
                }
            };

            if (Build.VERSION.SdkInt >= BuildVersionCodes.O)
            {
                mAudioFocusRequest = new AudioFocusRequestClass
                                     .Builder(AudioFocus.Gain)
                                     .SetAudioAttributes(mAudioAttributes)
                                     .SetAcceptsDelayedFocusGain(true)
                                     .SetOnAudioFocusChangeListener(mFocusListener)
                                     .Build();
            }
        }
Exemple #7
0
        public void CreateNotification(String title, String message)
        {
            try
            {
                var intent = new Intent(mContext, typeof(MainActivity));
                intent.AddFlags(ActivityFlags.ClearTop);
                intent.PutExtra(title, message);
                var pendingIntent = PendingIntent.GetActivity(mContext, 0, intent, PendingIntentFlags.OneShot);

                var sound = global::Android.Net.Uri.Parse(ContentResolver.SchemeAndroidResource + "://" + mContext.PackageName + "/" + Resource.Raw.ringtone);
                // Creating an Audio Attribute
                alarmAttributes = new AudioAttributes.Builder()
                                  .SetContentType(AudioContentType.Sonification)
                                  .SetUsage(AudioUsageKind.Notification).Build();

                mBuilder = new NotificationCompat.Builder(mContext);
                mBuilder.SetSmallIcon(Resource.Drawable.onlylogo);
                mBuilder.SetContentTitle(title)
                .SetSound(sound)
                .SetAutoCancel(false)
                .SetTimeoutAfter(25000)
                .SetContentTitle(title)
                .SetContentText(message)
                .SetChannelId(NOTIFICATION_CHANNEL_ID)
                .SetPriority(( int )NotificationPriority.High)
                .SetVibrate(new long [2])
                .SetDefaults(( int )NotificationDefaults.Sound | ( int )NotificationDefaults.Vibrate)
                .SetVisibility(( int )NotificationVisibility.Public)
                .SetColor(80)
                .SetVisibility(50)
                .SetContentIntent(pendingIntent);



                NotificationManager notificationManager = mContext.GetSystemService(Context.NotificationService) as NotificationManager;

                if (global::Android.OS.Build.VERSION.SdkInt >= global::Android.OS.BuildVersionCodes.O)
                {
                    NotificationImportance importance = global::Android.App.NotificationImportance.High;

                    NotificationChannel notificationChannel = new NotificationChannel(NOTIFICATION_CHANNEL_ID, title, importance);
                    notificationChannel.EnableLights(true);
                    notificationChannel.EnableVibration(true);
                    notificationChannel.SetSound(sound, alarmAttributes);
                    notificationChannel.SetShowBadge(true);
                    notificationChannel.Importance = NotificationImportance.High;
                    notificationChannel.SetVibrationPattern(new long [] { 100, 200, 300, 400, 500, 400, 300, 200, 400 });

                    if (notificationManager != null)
                    {
                        mBuilder.SetChannelId(NOTIFICATION_CHANNEL_ID);
                        notificationManager.CreateNotificationChannel(notificationChannel);
                    }
                }

                notificationManager.Notify(0, mBuilder.Build());
            }
            catch (Exception ex)
            {
                //
            }
        }