2

I am trying to play livestreaming .ogg audio through media player in my app on receiving a notification. My device has Oreo.The problem is, when ever I am recieving the notification, while trying to play the audio, I am getting the following exception:

D/MediaPlayer: setDataSource IOException | SecurityException happend : 
java.io.FileNotFoundException: No content provider: http://10.15.17.27:8000/40bccd94-9388-4e62-f2e4-08d65393ff81
    at android.content.ContentResolver.openTypedAssetFileDescriptor(ContentResolver.java:1402)
    at android.content.ContentResolver.openAssetFileDescriptor(ContentResolver.java:1253)
    at android.content.ContentResolver.openAssetFileDescriptor(ContentResolver.java:1176)
    at android.media.MediaPlayer.attemptDataSource(MediaPlayer.java:1163)
    at android.media.MediaPlayer.setDataSource(MediaPlayer.java:1135)
    at android.media.MediaPlayer.setDataSource(MediaPlayer.java:1080)
    at android.media.MediaPlayer.create(MediaPlayer.java:972)
    at android.media.MediaPlayer.create(MediaPlayer.java:949)
    at android.media.MediaPlayer.create(MediaPlayer.java:928)

Once the livestreaming is over,mediaplayer starts playing the finished live stream. Please find my code below:

  try {
            //  MediaPlayer player = MediaPlayer.create(this, Uri.parse(remoteMessage.getData().get("body")));
            MediaPlayer player = MediaPlayer.create(this, Uri.parse("http://10.15.17.27:8000/" + str_channel));
            player.setAudioStreamType(AudioManager.STREAM_MUSIC);
            player.setWakeMode(getApplicationContext(), PowerManager.PARTIAL_WAKE_LOCK);
            player.setOnPreparedListener(new MediaPlayer.OnPreparedListener() {
                @Override
                public void onPrepared(MediaPlayer mp) {
                    mp.start();
                }
            });
        } catch (Exception e) {
            Log.e("mediaplayerexc", e.getMessage());
        }
Animesh Jena
  • 1,541
  • 1
  • 25
  • 44
  • You need to check what is the audio codec for that file. Following are the supported codecs by android media player[Supported_codecs_mediaPlayer](https://developer.android.com/guide/topics/media/media-formats) – kiran Biradar Nov 27 '18 at 09:51

1 Answers1

2

you can't use plain-text HTTP, unless providing a network security configuration, which overrides the default network security configuration, which became cleartextTrafficPermitted="false". for example (only the base-config would be applicable, unless having a local DNS available). when your DSL router provides a domain, you could use domain-config and be more specific about it:

<?xml version="1.0" encoding="utf-8"?>
<base-config cleartextTrafficPermitted="true">
    <trust-anchors>
        <certificates src="system" />
    </trust-anchors>
</base-config>

this question also appears related - while Android Pie nevertheless needs the security configuration.

Martin Zeitler
  • 1
  • 19
  • 155
  • 216