Mediaplayer not playing audio from URL












0















Currently I'm working on my simple media audio player on Android Studio, and I'm trying play a sound from URL, but I'm getting a error, check my code below:



public class MainActivity extends AppCompatActivity {

public MediaPlayer mediaPlayer;
Handler handler;

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);

handler = new Handler();
final Runnable r = new Runnable() {
public void run() {
initAudio(getApplicationContext(), "http://ntcdn.stream/audio/teste.ogg");
handler.postDelayed(this, 1000);
}
};
handler.postDelayed(r, 1000);

}

public void initAudio(final Context context, String url) {
if (mediaPlayer == null) {
try {
mediaPlayer = new MediaPlayer();
mediaPlayer.setAudioStreamType(AudioManager.STREAM_MUSIC);
mediaPlayer = MediaPlayer.create(context, Uri.parse(url));
mediaPlayer.start();
} catch (Exception e) {
e.printStackTrace();
Toast.makeText(context, "Falha ao iniciar o áudio", Toast.LENGTH_LONG).show();
killMediaPlayer();
}
}
}


public void killMediaPlayer() {
if (mediaPlayer != null) {
try {
mediaPlayer.reset();
mediaPlayer.release();
mediaPlayer = null;
} catch (Exception e) {
e.printStackTrace();
}
}
}


I want create a loop to play the audio always, but I got this error from logcat:



11-22 03:12:24.051 29582-29582/etes.giuseppe.databringer V/MediaPlayer-JNI: setParameter: key 1400
11-22 03:12:24.051 29582-29582/etes.giuseppe.databringer V/MediaPlayer: MediaPlayer::setParameter(1400)
11-22 03:12:24.051 29582-29582/etes.giuseppe.databringer V/MediaPlayer-JNI: setAudioStreamType: 3
11-22 03:12:24.051 29582-29582/etes.giuseppe.databringer V/MediaPlayer: MediaPlayer::setAudioStreamType
11-22 03:12:24.051 29582-29582/etes.giuseppe.databringer V/MediaPlayer-JNI: set_session_id(): 8270
11-22 03:12:24.051 29582-29582/etes.giuseppe.databringer V/MediaPlayer: MediaPlayer::setAudioSessionId(8270)
11-22 03:12:24.051 29582-29582/etes.giuseppe.databringer W/MediaPlayer: Couldn't open file on client side; trying server side: java.io.FileNotFoundException: No content provider: http://ntcdn.stream/audio/teste.ogg
11-22 03:12:24.051 29582-29582/etes.giuseppe.databringer D/RingtoneManager: Can't get current user. return default user
11-22 03:12:24.051 29582-29582/etes.giuseppe.databringer D/MediaPlayer: setDataSource IOException | SecurityException happend :
java.io.FileNotFoundException: No content provider: http://ntcdn.stream/audio/teste.ogg


Can you help me? I really don't know what I should do to fix this problem. Thank you.










share|improve this question























  • Check if your url is correct and you're authorised to play it because the stack trace tells that the file was not found at that location.

    – PradyumanDixit
    Nov 22 '18 at 5:36











  • The URL is correct, just check it by yourself at thread, and I've added all permissions at my manifest, still not working.

    – inukix
    Nov 22 '18 at 5:38
















0















Currently I'm working on my simple media audio player on Android Studio, and I'm trying play a sound from URL, but I'm getting a error, check my code below:



public class MainActivity extends AppCompatActivity {

public MediaPlayer mediaPlayer;
Handler handler;

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);

handler = new Handler();
final Runnable r = new Runnable() {
public void run() {
initAudio(getApplicationContext(), "http://ntcdn.stream/audio/teste.ogg");
handler.postDelayed(this, 1000);
}
};
handler.postDelayed(r, 1000);

}

public void initAudio(final Context context, String url) {
if (mediaPlayer == null) {
try {
mediaPlayer = new MediaPlayer();
mediaPlayer.setAudioStreamType(AudioManager.STREAM_MUSIC);
mediaPlayer = MediaPlayer.create(context, Uri.parse(url));
mediaPlayer.start();
} catch (Exception e) {
e.printStackTrace();
Toast.makeText(context, "Falha ao iniciar o áudio", Toast.LENGTH_LONG).show();
killMediaPlayer();
}
}
}


public void killMediaPlayer() {
if (mediaPlayer != null) {
try {
mediaPlayer.reset();
mediaPlayer.release();
mediaPlayer = null;
} catch (Exception e) {
e.printStackTrace();
}
}
}


I want create a loop to play the audio always, but I got this error from logcat:



11-22 03:12:24.051 29582-29582/etes.giuseppe.databringer V/MediaPlayer-JNI: setParameter: key 1400
11-22 03:12:24.051 29582-29582/etes.giuseppe.databringer V/MediaPlayer: MediaPlayer::setParameter(1400)
11-22 03:12:24.051 29582-29582/etes.giuseppe.databringer V/MediaPlayer-JNI: setAudioStreamType: 3
11-22 03:12:24.051 29582-29582/etes.giuseppe.databringer V/MediaPlayer: MediaPlayer::setAudioStreamType
11-22 03:12:24.051 29582-29582/etes.giuseppe.databringer V/MediaPlayer-JNI: set_session_id(): 8270
11-22 03:12:24.051 29582-29582/etes.giuseppe.databringer V/MediaPlayer: MediaPlayer::setAudioSessionId(8270)
11-22 03:12:24.051 29582-29582/etes.giuseppe.databringer W/MediaPlayer: Couldn't open file on client side; trying server side: java.io.FileNotFoundException: No content provider: http://ntcdn.stream/audio/teste.ogg
11-22 03:12:24.051 29582-29582/etes.giuseppe.databringer D/RingtoneManager: Can't get current user. return default user
11-22 03:12:24.051 29582-29582/etes.giuseppe.databringer D/MediaPlayer: setDataSource IOException | SecurityException happend :
java.io.FileNotFoundException: No content provider: http://ntcdn.stream/audio/teste.ogg


Can you help me? I really don't know what I should do to fix this problem. Thank you.










share|improve this question























  • Check if your url is correct and you're authorised to play it because the stack trace tells that the file was not found at that location.

    – PradyumanDixit
    Nov 22 '18 at 5:36











  • The URL is correct, just check it by yourself at thread, and I've added all permissions at my manifest, still not working.

    – inukix
    Nov 22 '18 at 5:38














0












0








0








Currently I'm working on my simple media audio player on Android Studio, and I'm trying play a sound from URL, but I'm getting a error, check my code below:



public class MainActivity extends AppCompatActivity {

public MediaPlayer mediaPlayer;
Handler handler;

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);

handler = new Handler();
final Runnable r = new Runnable() {
public void run() {
initAudio(getApplicationContext(), "http://ntcdn.stream/audio/teste.ogg");
handler.postDelayed(this, 1000);
}
};
handler.postDelayed(r, 1000);

}

public void initAudio(final Context context, String url) {
if (mediaPlayer == null) {
try {
mediaPlayer = new MediaPlayer();
mediaPlayer.setAudioStreamType(AudioManager.STREAM_MUSIC);
mediaPlayer = MediaPlayer.create(context, Uri.parse(url));
mediaPlayer.start();
} catch (Exception e) {
e.printStackTrace();
Toast.makeText(context, "Falha ao iniciar o áudio", Toast.LENGTH_LONG).show();
killMediaPlayer();
}
}
}


public void killMediaPlayer() {
if (mediaPlayer != null) {
try {
mediaPlayer.reset();
mediaPlayer.release();
mediaPlayer = null;
} catch (Exception e) {
e.printStackTrace();
}
}
}


I want create a loop to play the audio always, but I got this error from logcat:



11-22 03:12:24.051 29582-29582/etes.giuseppe.databringer V/MediaPlayer-JNI: setParameter: key 1400
11-22 03:12:24.051 29582-29582/etes.giuseppe.databringer V/MediaPlayer: MediaPlayer::setParameter(1400)
11-22 03:12:24.051 29582-29582/etes.giuseppe.databringer V/MediaPlayer-JNI: setAudioStreamType: 3
11-22 03:12:24.051 29582-29582/etes.giuseppe.databringer V/MediaPlayer: MediaPlayer::setAudioStreamType
11-22 03:12:24.051 29582-29582/etes.giuseppe.databringer V/MediaPlayer-JNI: set_session_id(): 8270
11-22 03:12:24.051 29582-29582/etes.giuseppe.databringer V/MediaPlayer: MediaPlayer::setAudioSessionId(8270)
11-22 03:12:24.051 29582-29582/etes.giuseppe.databringer W/MediaPlayer: Couldn't open file on client side; trying server side: java.io.FileNotFoundException: No content provider: http://ntcdn.stream/audio/teste.ogg
11-22 03:12:24.051 29582-29582/etes.giuseppe.databringer D/RingtoneManager: Can't get current user. return default user
11-22 03:12:24.051 29582-29582/etes.giuseppe.databringer D/MediaPlayer: setDataSource IOException | SecurityException happend :
java.io.FileNotFoundException: No content provider: http://ntcdn.stream/audio/teste.ogg


Can you help me? I really don't know what I should do to fix this problem. Thank you.










share|improve this question














Currently I'm working on my simple media audio player on Android Studio, and I'm trying play a sound from URL, but I'm getting a error, check my code below:



public class MainActivity extends AppCompatActivity {

public MediaPlayer mediaPlayer;
Handler handler;

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);

handler = new Handler();
final Runnable r = new Runnable() {
public void run() {
initAudio(getApplicationContext(), "http://ntcdn.stream/audio/teste.ogg");
handler.postDelayed(this, 1000);
}
};
handler.postDelayed(r, 1000);

}

public void initAudio(final Context context, String url) {
if (mediaPlayer == null) {
try {
mediaPlayer = new MediaPlayer();
mediaPlayer.setAudioStreamType(AudioManager.STREAM_MUSIC);
mediaPlayer = MediaPlayer.create(context, Uri.parse(url));
mediaPlayer.start();
} catch (Exception e) {
e.printStackTrace();
Toast.makeText(context, "Falha ao iniciar o áudio", Toast.LENGTH_LONG).show();
killMediaPlayer();
}
}
}


public void killMediaPlayer() {
if (mediaPlayer != null) {
try {
mediaPlayer.reset();
mediaPlayer.release();
mediaPlayer = null;
} catch (Exception e) {
e.printStackTrace();
}
}
}


I want create a loop to play the audio always, but I got this error from logcat:



11-22 03:12:24.051 29582-29582/etes.giuseppe.databringer V/MediaPlayer-JNI: setParameter: key 1400
11-22 03:12:24.051 29582-29582/etes.giuseppe.databringer V/MediaPlayer: MediaPlayer::setParameter(1400)
11-22 03:12:24.051 29582-29582/etes.giuseppe.databringer V/MediaPlayer-JNI: setAudioStreamType: 3
11-22 03:12:24.051 29582-29582/etes.giuseppe.databringer V/MediaPlayer: MediaPlayer::setAudioStreamType
11-22 03:12:24.051 29582-29582/etes.giuseppe.databringer V/MediaPlayer-JNI: set_session_id(): 8270
11-22 03:12:24.051 29582-29582/etes.giuseppe.databringer V/MediaPlayer: MediaPlayer::setAudioSessionId(8270)
11-22 03:12:24.051 29582-29582/etes.giuseppe.databringer W/MediaPlayer: Couldn't open file on client side; trying server side: java.io.FileNotFoundException: No content provider: http://ntcdn.stream/audio/teste.ogg
11-22 03:12:24.051 29582-29582/etes.giuseppe.databringer D/RingtoneManager: Can't get current user. return default user
11-22 03:12:24.051 29582-29582/etes.giuseppe.databringer D/MediaPlayer: setDataSource IOException | SecurityException happend :
java.io.FileNotFoundException: No content provider: http://ntcdn.stream/audio/teste.ogg


Can you help me? I really don't know what I should do to fix this problem. Thank you.







java android-studio android-mediaplayer






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Nov 22 '18 at 5:19









inukixinukix

446




446













  • Check if your url is correct and you're authorised to play it because the stack trace tells that the file was not found at that location.

    – PradyumanDixit
    Nov 22 '18 at 5:36











  • The URL is correct, just check it by yourself at thread, and I've added all permissions at my manifest, still not working.

    – inukix
    Nov 22 '18 at 5:38



















  • Check if your url is correct and you're authorised to play it because the stack trace tells that the file was not found at that location.

    – PradyumanDixit
    Nov 22 '18 at 5:36











  • The URL is correct, just check it by yourself at thread, and I've added all permissions at my manifest, still not working.

    – inukix
    Nov 22 '18 at 5:38

















Check if your url is correct and you're authorised to play it because the stack trace tells that the file was not found at that location.

– PradyumanDixit
Nov 22 '18 at 5:36





Check if your url is correct and you're authorised to play it because the stack trace tells that the file was not found at that location.

– PradyumanDixit
Nov 22 '18 at 5:36













The URL is correct, just check it by yourself at thread, and I've added all permissions at my manifest, still not working.

– inukix
Nov 22 '18 at 5:38





The URL is correct, just check it by yourself at thread, and I've added all permissions at my manifest, still not working.

– inukix
Nov 22 '18 at 5:38












1 Answer
1






active

oldest

votes


















0














use this:



private void startPlaying() {
mediaPlayer = new MediaPlayer();
try {
mediaPlayer.setDataSource(YOUR_URL);
mediaPlayer.prepare();
} catch (IOException ignored) {
}
mediaPlayer.start();
}





share|improve this answer























    Your Answer






    StackExchange.ifUsing("editor", function () {
    StackExchange.using("externalEditor", function () {
    StackExchange.using("snippets", function () {
    StackExchange.snippets.init();
    });
    });
    }, "code-snippets");

    StackExchange.ready(function() {
    var channelOptions = {
    tags: "".split(" "),
    id: "1"
    };
    initTagRenderer("".split(" "), "".split(" "), channelOptions);

    StackExchange.using("externalEditor", function() {
    // Have to fire editor after snippets, if snippets enabled
    if (StackExchange.settings.snippets.snippetsEnabled) {
    StackExchange.using("snippets", function() {
    createEditor();
    });
    }
    else {
    createEditor();
    }
    });

    function createEditor() {
    StackExchange.prepareEditor({
    heartbeatType: 'answer',
    autoActivateHeartbeat: false,
    convertImagesToLinks: true,
    noModals: true,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: 10,
    bindNavPrevention: true,
    postfix: "",
    imageUploader: {
    brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
    contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
    allowUrls: true
    },
    onDemand: true,
    discardSelector: ".discard-answer"
    ,immediatelyShowMarkdownHelp:true
    });


    }
    });














    draft saved

    draft discarded


















    StackExchange.ready(
    function () {
    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53424312%2fmediaplayer-not-playing-audio-from-url%23new-answer', 'question_page');
    }
    );

    Post as a guest















    Required, but never shown

























    1 Answer
    1






    active

    oldest

    votes








    1 Answer
    1






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes









    0














    use this:



    private void startPlaying() {
    mediaPlayer = new MediaPlayer();
    try {
    mediaPlayer.setDataSource(YOUR_URL);
    mediaPlayer.prepare();
    } catch (IOException ignored) {
    }
    mediaPlayer.start();
    }





    share|improve this answer




























      0














      use this:



      private void startPlaying() {
      mediaPlayer = new MediaPlayer();
      try {
      mediaPlayer.setDataSource(YOUR_URL);
      mediaPlayer.prepare();
      } catch (IOException ignored) {
      }
      mediaPlayer.start();
      }





      share|improve this answer


























        0












        0








        0







        use this:



        private void startPlaying() {
        mediaPlayer = new MediaPlayer();
        try {
        mediaPlayer.setDataSource(YOUR_URL);
        mediaPlayer.prepare();
        } catch (IOException ignored) {
        }
        mediaPlayer.start();
        }





        share|improve this answer













        use this:



        private void startPlaying() {
        mediaPlayer = new MediaPlayer();
        try {
        mediaPlayer.setDataSource(YOUR_URL);
        mediaPlayer.prepare();
        } catch (IOException ignored) {
        }
        mediaPlayer.start();
        }






        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered Nov 22 '18 at 9:21









        Shahriyar AghajaniShahriyar Aghajani

        74112




        74112
































            draft saved

            draft discarded




















































            Thanks for contributing an answer to Stack Overflow!


            • Please be sure to answer the question. Provide details and share your research!

            But avoid



            • Asking for help, clarification, or responding to other answers.

            • Making statements based on opinion; back them up with references or personal experience.


            To learn more, see our tips on writing great answers.




            draft saved


            draft discarded














            StackExchange.ready(
            function () {
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53424312%2fmediaplayer-not-playing-audio-from-url%23new-answer', 'question_page');
            }
            );

            Post as a guest















            Required, but never shown





















































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown

































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown







            Popular posts from this blog

            MongoDB - Not Authorized To Execute Command

            How to fix TextFormField cause rebuild widget in Flutter

            in spring boot 2.1 many test slices are not allowed anymore due to multiple @BootstrapWith