Answer the question
In order to leave comments, you need to log in
The audio stream plays after a few seconds, why?
Good evening.
I threw in the code for playing the audio stream (namely, the radio), I run it on the emulator, I press the start button and the playback starts immediately. On the physical device, after about 30 seconds, what was most interesting in the logs was just the lineb
03-17 23:24:03.809 18672-18684/com.example.radioplayer V/MediaHTTPConnection: mTotalSize is -1
03-17 23:24 :03.819 18672-18682/com.example.radioplayer D/MediaHTTPConnection: setReadTimeOut = 30000ms
Here is the code:
package com.example.radioplayer;
import android.media.AudioManager;
import android.media.MediaPlayer;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.widget.Button;
import java.io.IOException;
public class MainActivity extends AppCompatActivity {
Button button_stop;
Button button_play;
public String STREAM_URL = "http://icecast.piktv.cdnvideo.ru/vanya?47";
private MediaPlayer mPlayer;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
button_stop=(Button) findViewById(R.id.stop);
button_play=(Button) findViewById(R.id.start);
button_stop.setEnabled(false);
mPlayer=new MediaPlayer();
mPlayer.setAudioStreamType(AudioManager.STREAM_MUSIC);
button_play.setOnClickListener(new View.OnClickListener(){
@Override
public void onClick(View v){
mPlayer.reset();
try {
mPlayer.setDataSource(STREAM_URL);
} catch (IOException e) {
e.printStackTrace();
}
mPlayer.prepareAsync();
mPlayer.setOnPreparedListener(new MediaPlayer.OnPreparedListener() {
@Override
public void onPrepared(MediaPlayer mp) {
mp.start();
}
});
button_play.setEnabled(false);
button_stop.setEnabled(true);
}
});
button_stop.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
mPlayer.stop();
button_stop.setEnabled(false);
button_play.setEnabled(true);
}
});
}
}
Answer the question
In order to leave comments, you need to log in
Physical device Samsung Galaxys* ? Android 4.4 or more?
This is a device problem, I solved this problem by connecting another library - Vitamio (connect only the 5th version, but not lower, otherwise a warning will appear in the console that you need to switch to the 5th version, otherwise the application will be blocked, because in the version below there is a vulnerability).
You can see how to connect the library and how to work with it on the site, on github and on stackoverflow .... in general, there is a lot of information
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question