Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Android : Issue having multiple sounds #448

Open
Bebz0r opened this issue Sep 1, 2023 · 11 comments
Open

Android : Issue having multiple sounds #448

Bebz0r opened this issue Sep 1, 2023 · 11 comments
Assignees
Labels
Android Android only issue Configuration Issue Configuration Issue

Comments

@Bebz0r
Copy link

Bebz0r commented Sep 1, 2023

Hi there,

First, thanks a lot about your fantastic work, @thudugala, the functionnality and usage is really simple and straightforward.

However, I can't make multiple sounds to work on Android. One works fine, but if I want to add more, it does not work : only the first one I declare in .AddAndroid is played :

My files (legit_01.mp3 and legit_02.mp3) are located in Platforms/Android/Resources/raw

I did some tests (uninstalling / reinstalling the app before each test).

Here is how I call my notification. I want to be able to change the sound just by changing "legit_01" to "legit_02" :

// Create the request itself
var request = new NotificationRequest
{
	NotificationId = Convert.ToInt32(NotificationId),
	Title = $"{theNotif.Description} coming at {theNotif.TimeEvent:HH:mm}",
	Subtitle = "", // Appear on the right side of the title (optionnal)
	Description = theNotif.Category,
	// CategoryType, defined in MauiProgram.cs' config is the list of buttons available for actions
	CategoryType = NotificationCategoryType.Status,
	Sound = DeviceInfo.Platform == DevicePlatform.Android ? "legit_01" : "legit_01.mp3", // or legit_02
	Schedule = new NotificationRequestSchedule
	{
		// Set it based on the week day
		NotifyTime = TargetDate,
		RepeatType = NotificationRepeat.TimeInterval,
		NotifyRepeatInterval = TimeSpan.FromDays(7)
	}
};
LocalNotificationCenter.Current.Show(request);

And how I create my two channels :

.UseLocalNotification(config =>
{
	config.AddCategory(new NotificationCategory(NotificationCategoryType.Status)
	{
		ActionList = new HashSet<NotificationAction>(new List<NotificationAction>()
				{
					new NotificationAction(1337)
					{
						Title = "MUTE",
						Android = { LaunchAppWhenTapped = true }
					}
				})
	})
	.AddAndroid(android =>
	{
		android.AddChannel(new NotificationChannelRequest { Sound = "legit_01" });
		android.AddChannel(new NotificationChannelRequest { Sound = "legit_02" });
	});
})

After multiple tests, it's always the first one defined in .AddAndroid that is played, whatever the value of the "Sound" parameter I give to the NotificationRequest. If I switch the AddChannel (e.g. : legit_02 first), it will play legit_02 first, no matter which legit_XX I put in the "Sound" parameter. If I give a random "Sound" parameter though, no sound is played - as if it didn't find the file (which is correct and expected).

Based on the docs, I tried to add Id and Names to the Channels, like so :

.UseLocalNotification(config =>
{
	config.AddCategory(new NotificationCategory(NotificationCategoryType.Status)
	{
		ActionList = new HashSet<NotificationAction>(new List<NotificationAction>()
				{
					new NotificationAction(1337)
					{
						Title = "MUTE",
						Android = { LaunchAppWhenTapped = true }
					}
				})
	})
	.AddAndroid(android =>
	{
		android.AddChannel(new NotificationChannelRequest { Id=$"legit_01", Name="legit_01", Description="legit_01", Sound = "legit_01" });
		android.AddChannel(new NotificationChannelRequest { Id=$"legit_02", Name="legit_02", Description="legit_02", Sound = "legit_02" });
	});
})

But this behaves even worse : the default sound of my device (which is already a custom one) is played.

@Bebz0r Bebz0r added the bug Something isn't working label Sep 1, 2023
@thudugala
Copy link
Owner

@Bebz0r Can you please attach a sample project?

@thudugala thudugala added the Android Android only issue label Sep 1, 2023
@Bebz0r
Copy link
Author

Bebz0r commented Sep 1, 2023

Sure, let me create one from scratch, I'll keep you posted

@Bebz0r
Copy link
Author

Bebz0r commented Sep 1, 2023

Here you go, I created a sample project reproducing the issue : https://github.com/Bebz0r/TestSoundNotification

@Bebz0r
Copy link
Author

Bebz0r commented Sep 1, 2023

By the way, from my tests, it seems that (at least on Android), the mp3 files :

  • Have to respect Android naming convention (everything in lowercase letters)
  • Must be 128kps (320kps didn't played)
    This could be a nice addition to the read me

@thudugala
Copy link
Owner

thudugala commented Sep 9, 2023

@Bebz0r Is your issue fixed after fixing bit rate and name of the file ?

Documentation updated

@Bebz0r
Copy link
Author

Bebz0r commented Sep 10, 2023

Hi @thudugala ,
No, the issue still happens, my remark was just a random finding :) Thanks for updating the docs.

@thudugala
Copy link
Owner

thudugala commented Sep 29, 2023

@Bebz0r Have you specified the ChannelId in NotificationRequest?

https://github.com/thudugala/Plugin.LocalNotification/wiki/Notification-with-a-Sound-File

image

@thudugala thudugala added Configuration Issue Configuration Issue and removed bug Something isn't working labels Sep 29, 2023
@pelka-mariusz
Copy link

Hi,
I have the same problem with multiple audio files. Only the first file works.

@thudugala
Copy link
Owner

@pelka-mariusz can you please attach a sample project?

@pelka-mariusz
Copy link

Hi,
MauiApp1.zip

An example project is attached. Not any sound is played. Tested on Pixel 5 emulator - API 34 (Android 14.0 - API 34).

@pelka-mariusz
Copy link

Hi,

did you manage to solve the problem?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Android Android only issue Configuration Issue Configuration Issue
Projects
None yet
Development

No branches or pull requests

3 participants