0

Android Studio says 'Unexpected tokens' when I add mp3 file in res directory on my project I am trying to add custom sound to firebase push notification, but when I paste the .mp3 file into the raw directory it gives an error.Unexpected tokens

  • What is the name of your .mp3 file? Android studio cannot use names like "my-song.mp3" or non-English characters while parsing raw resources. Try changing it to something like "my_song.mp3" with underscores instead of minus. – Furkan Yurdakul Aug 21 '19 at 12:06

2 Answers2

0

Try putting the mp3 file in asset folder, this would be my first try.

If issue is still there then maybe the mp3 is not impure, try replacing it with some other one to test it out

hardik9850
  • 581
  • 1
  • 9
  • 26
  • After putting in asset folder or with other mp3 file? – hardik9850 Aug 21 '19 at 11:49
  • I put this mp3 in same location as yours and it worked for me https://file-examples.com/wp-content/uploads/2017/11/file_example_MP3_700KB.mp3 Looks like your mp3 file is impure for studio to parse – hardik9850 Aug 21 '19 at 12:27
  • since you are able to compile the code, this warning shouldn't bother you. and for setting the audio as notification alert sound you have to make changes in Notification API https://stackoverflow.com/a/31398504/2606144 – hardik9850 Aug 21 '19 at 12:33
0

This is a non-issue. It makes sense you can't open a sound file in a text editor view.

Because the MP3's are in the raw directory, I don't think android will try to interpret the contents. Does the app compile? Can you use the mp3 in your app however you were trying? If so, don't worry about this issue.

However, if the app will not compile or it really bothers you, then you probably need to teach the IDE to associate MP3 files with a media player.

There is another answer on StackOverflow for associating files, here

Nick Cardoso
  • 20,807
  • 14
  • 73
  • 124
  • the app compiles and also I can use the file, but when a notification comes to phone it didn't use the added sound file it uses phones default sound. – abhishek ghatge Aug 21 '19 at 12:06
  • Well programmatically setting/using a custom sound for notification is a different, complicated issue so you can search for that or open a new question. For getting rid of the "unexpected token" as this question asks, the link I've given should help you. Good luck – Nick Cardoso Aug 21 '19 at 12:09
  • could please tell me how to add a sound file to firebase push notification in android studio. when a notification comes to phone the alert sound of that notification must be our added mp3 file, not the system default notification sound. – abhishek ghatge Aug 21 '19 at 12:10
  • 'add a sound file to firebase' - that's a new question you could open. But my 2-cents is that it is a bad idea – Nick Cardoso Aug 22 '19 at 09:32