Cannot play default notification ringtone on some device - android

Here is my code snippet to play ringtone notification:
Uri u = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);
Ringtone r = RingtoneManager.getRingtone(MainActivity.this, u);
r.play();
This seems to work fine on most devices. However, on some devices such as Samsung S8 and Samsung S9, it does not work. Logcat shows:
I/Ringtone: Internal uri : content://settings/system/notification_sound
D/RingtoneManager: getActualDefaultRingtoneUri type :2
W/MediaPlayer: Couldn't open content://0#settings/system/notification_sound_cache:
java.io.FileNotFoundException: open failed: ENOENT (No such file or directory)
Note that the same code works fine on Samsung S7.
Wondering if anyone has any insight.

Related

How to use DownloadManager on Android 10?

I want to use DownloadManager on Android 10 to download files, and a download progress notification bar will appear.
I use the following code, which can be used normally on devices under Android 9 but not on Android 10 emulator (no error exception message appears). The download progress notification bar does not appear on the notification bar, but I notice This file appeared in the "Files" app of the system and was not downloaded because its raw size (bytes) is always -1.
How can I modify my code so that it can be used on Android 10, thank you very much!
var request = DownloadManager.Request(Uri.parse(downloadUrl))
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q) {
request.setDestinationInExternalPublicDir(Environment.DIRECTORY_DOWNLOADS, saveName)
} else {
request.setDestinationInExternalFilesDir(context, Environment.DIRECTORY_DOWNLOADS, saveName)
}
request.setAllowedNetworkTypes(
DownloadManager.Request.NETWORK_MOBILE or DownloadManager.Request.NETWORK_WIFI
)
request.setNotificationVisibility(
DownloadManager.Request.VISIBILITY_VISIBLE_NOTIFY_COMPLETED
)
request.setTitle("TEST")
request.setDescription("TEST")
downloadManager.enqueue(request)
Screenshot of the system app "File"
Screenshot of the system app "File"2
From the test results, this problem may be a bug in the simulator, because I did not test this problem on real devices (Samsung s10, Samsung note9, Xiaomi 8, Google nexus6P), but I have no more real devices , So if you have this problem with other real devices, please let me know.

Android: pcm_open failed cannot open device '/dev/snd/pcmC0D1p'

A custom piece of hardware is running Android with the audio drivers installed.
An simple Android app is created to play some audio using media player, the app is tested on a emulator so it works for sure.
When running the device on the hardware, error message from logcat displays the following many times:
01-01 01:09:16.355 2792-3186/? E/audio_hw_primary﹕ pcm_open(PCM_CARD) failed: cannot open device '/dev/snd/pcmC0D1p': No such file or directory
01-01 01:09:16.375 2792-3186/? E/audio_hw_primary﹕ pcm_open(PCM_CARD) failed: cannot open device '/dev/snd/pcmC0D1p': No such file or directory
01-01 01:09:16.435 2792-375/? E/AudioSink﹕ received unknown event type: 1 inside CallbackWrapper !
under /dev/snd/ there are
controlC0
pcmC0D0c
pcmC0D0p
timer
I am able to play system notifications without any problem. I could also hack the problem by creating a symbolic link pcmC0D1p pointing to pcmC0D0p, and it works. Why is android trying to play non-system sound track on pcmC0D1p? Who is controlling which output it goes to?
pcmC0D1p means :
pcm
Card 0
Device 1
Capture/Playback p
Clearly, whatever the node your app is accessing is not present as seen through your ls /dev/snd/.
Normally, if you are playing non-standard sounds like mp3 files, writing to AudioTrack, will handle everything.
If you see only one playback node by doing ls /dev/snd, it means you have only one playback node present, which I think (not sure though) is occupied for standard android sounds.
If "pcmC0D1p" device is present in /dev/snd then try to give permission with command
chmod 777 /dev/snd/pcmC0D1p
If it is still not working then this sound card is not available.

Streaming m3u8 HLS Audio on Android

i've found problems trying to reproduce m3u8 HLS audio streaming on Android. Right now i can reproduce video in m3u8 HLS link with:
Intent i = new Intent(Intent.ACTION_VIEW);
i.setDataAndType(Uri.parse(contentURL),"video/mp4");
startActivityForResult(i,0)
I've already tried this method:
number 1:
Intent i = new Intent(Intent.ACTION_VIEW);
i.setDataAndType(Uri.parse(contentURL),"video/mp4");
startActivityForResult(i,0)
number 2:
Intent i = new Intent(Intent.ACTION_VIEW);
i.setDataAndType(Uri.parse(contentURL),"audio/mp3");
startActivityForResult(i,0)
number 3:
MediaPlayer mediaPlayer = MediaPlayer.create(this, Uri.parse("http:\\testexample.m3u8"));
mediaPlayer.start();
In case 3 the error on log like "mediaserver Died", in case 1 and 2 simply the phone gallery said "can't reproduce video" or "can't reproduce this kind of file".
Last but not the least, if i send the http m3u8 link with an email at a Nexus 4 with Android 4.3, it open the link with chrome, then ask to open phone galleryplayer, and reproduce it. The same thing done with da SII with cyanogenmod and android 4.2.1 said, as before, "cannot reproduce video".
Put your code In try-catch block.
Set onPreparedListenet() and prepareAsync(), then on the onPrepared() callback start playback.

Android - What does MEDIA ERROR UNKNOWN -1 ussually means

I'm developing an Audio Player (using the MediaPlayer) which works fine on mdpi, hdpi, tablets, but throws a error: MEDIA ERROR UNKNOWN -1 on Samsung Galaxy mini (ldpi).
What I noticed is that this error occurs for majority of songs, though there are 1, 2 songs that still plays on Galaxy Mini.
Why does this error usually occurs?
I managed to know what was the problem by passing the same URI that was causing the issue to the native Audio Player and let see how it will react. The native audio player responded in a more user-friendly way, by saying that the file type is not supported.
So at least now I know the problem is not from my side.
private void startNativeAudioPlayer() {
String path="http://..";
Intent intent = new Intent();
intent.setAction(android.content.Intent.ACTION_VIEW);
intent.setDataAndType(Uri.parse(path), "audio/*");
startActivity(intent);
}

No sound on Android when streaming audio in AIR

I'm working on an app to stream audio from shoutcast. The streaming goes well on my computer and when debugging it with an Android-configuration.
But when I deploy it to an APK-file and run it on a Samsung Galaxy S, the streaming doesn't work.
My code for streaming the audio:
var urlRequest:URLRequest = new URLRequest("http://.../;");
var soundContext:SoundLoaderContext = new SoundLoaderContext(2000, true);
soundChannel = new SoundChannel();
sound = new Sound(urlRequest, soundContext);
soundChannel = sound.play();
I've also tried an addEventListener(Event.COMPLETE), it seems my app doesn't get there when running on a Samsung Galaxy.
Pls check internet enabled descripted files.
http://help.adobe.com/en_US/air/build/WSfffb011ac560372f-5d0f4f25128cc9cd0cb-7ffc.html
Reffer Also
http://cookbooks.adobe.com/post_Playing_mp3_files_on_Flex_Mobile-19106.html

Categories

Resources