Mediaplayer not playing audio from URL
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

add a comment |
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

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
add a comment |
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

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

java

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
add a comment |
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
add a comment |
1 Answer
1
active
oldest
votes
use this:
private void startPlaying() {
mediaPlayer = new MediaPlayer();
try {
mediaPlayer.setDataSource(YOUR_URL);
mediaPlayer.prepare();
} catch (IOException ignored) {
}
mediaPlayer.start();
}
add a comment |
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
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
use this:
private void startPlaying() {
mediaPlayer = new MediaPlayer();
try {
mediaPlayer.setDataSource(YOUR_URL);
mediaPlayer.prepare();
} catch (IOException ignored) {
}
mediaPlayer.start();
}
add a comment |
use this:
private void startPlaying() {
mediaPlayer = new MediaPlayer();
try {
mediaPlayer.setDataSource(YOUR_URL);
mediaPlayer.prepare();
} catch (IOException ignored) {
}
mediaPlayer.start();
}
add a comment |
use this:
private void startPlaying() {
mediaPlayer = new MediaPlayer();
try {
mediaPlayer.setDataSource(YOUR_URL);
mediaPlayer.prepare();
} catch (IOException ignored) {
}
mediaPlayer.start();
}
use this:
private void startPlaying() {
mediaPlayer = new MediaPlayer();
try {
mediaPlayer.setDataSource(YOUR_URL);
mediaPlayer.prepare();
} catch (IOException ignored) {
}
mediaPlayer.start();
}
answered Nov 22 '18 at 9:21
Shahriyar AghajaniShahriyar Aghajani
74112
74112
add a comment |
add a comment |
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.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
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
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