我正在开发流媒体应用。虽然我已经使用java很长一段时间了,但我是Android的新手并没有直截了当地发现它。 首先,使用Android Media播放器工作正常,直到几周后,它停止工作。我联系了流媒体代理,他们解释说他们没有改变任何东西,并进一步补充说这是一个编码问题让我感到困惑。那为什么以前呢?
建议使用AAC编码器。我不知道如何在Mediaplayer中使用编码器...... 流媒体链接是playlist.m3u8格式。 谁可以帮助我?我真的很想知道为什么应用程序首先停止流式传输。
package com.example.yoyojojo.first_streaming;
import android.media.AudioManager;
import android.media.MediaPlayer;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.RadioButton;
import android.widget.RadioGroup;
import android.widget.TextView;
import android.widget.Toast;
public class MainActivity extends AppCompatActivity {
private MediaPlayer mPlayer = new MediaPlayer();
private Button buttonPlay;
private Button buttonStop;
private String url = "http://aztecalive-lh.akamaihd.net/i/0qeij0bji_1@26639/index_2_av-b.m3u8"; //I am having problems with this type of links .m3u8
private String url2 = "http://bbcmedia.ic.llnwd.net/stream/bbcmedia_radio2_mf_p";
private String url3 = "http://usa8-vn.mixstream.net:8138";
private RadioGroup radioStation;
private RadioButton selectedStation;
private RadioButton editStation;
private TextView text;
private EditText newUrlEntry;
private CharSequence bbc = "BBC", usa = "Shoutcast USA", guru = "GuruMP3";
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
mPlayer.setAudioStreamType(AudioManager.STREAM_MUSIC);
radioStation = (RadioGroup) findViewById(R.id.radioStation);
text = (TextView) findViewById(R.id.textV);
buttonPlay = (Button) findViewById(R.id.play);
newUrlEntry = (EditText) findViewById(R.id.editText);
editStation = (RadioButton) findViewById(R.id.editStation);
buttonPlay.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
int selectedId = radioStation.getCheckedRadioButtonId();
selectedStation = (RadioButton) findViewById(selectedId);
String choice = selectedStation.getText().toString();
text.setText("Station: "+choice);
String streamUrl = "";
switch(choice) {
case "BBC":
streamUrl = url2;
break;
case "Shoutcast USA":
streamUrl = url3;
break;
case "GuruMP3":
streamUrl = url;
break;
case "Enter URL":
streamUrl = newUrlEntry.getText().toString();
text.setText("Station: "+streamUrl.substring(0, 10));
break;
default:
break;
}
mPlayer = new MediaPlayer();
mPlayer.setAudioStreamType(AudioManager.STREAM_MUSIC);
try {
mPlayer.setDataSource(streamUrl);
mPlayer.prepare();
} catch (Exception e) {
Toast.makeText(getApplicationContext(), e.getMessage(), Toast.LENGTH_LONG).show();
}
mPlayer.start();
}
});
buttonStop = (Button) findViewById(R.id.stop);
buttonStop.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
// TODO Auto-generated method stub
if(mPlayer!=null && mPlayer.isPlaying()){
mPlayer.stop();
}
}
});
}
}
以下是生成的错误:
06-21 18:00:17.116 18668-18668/com.example.yoyojojo.appstream2 D/Starting: Starting Streaming
06-21 18:00:20.218 18668-18681/com.example.yoyojojo.appstream2 W/IMediaDeathNotifier: media server died
06-21 18:00:20.218 18668-18681/com.example.yoyojojo.appstream2 E/MediaPlayer: error (100, 0)
06-21 18:00:20.218 18668-18681/com.example.yoyojojo.appstream2 E/MediaPlayer: error (100, 0)
06-21 18:00:20.218 18668-18681/com.example.yoyojojo.appstream2 E/MediaPlayer: error (100, 0)
06-21 18:00:20.218 18668-18668/com.example.yoyojojo.appstream2 D/Starting: Prepare failed.: status=0x64
06-21 18:00:20.221 18668-18668/com.example.yoyojojo.appstream2 E/MediaPlayer: start called in state 0, mPlayer(0x9fd96d40)
06-21 18:00:20.221 18668-18668/com.example.yoyojojo.appstream2 E/MediaPlayer: error (-38, 0)
06-21 18:00:20.222 18668-18668/com.example.yoyojojo.appstream2 I/Choreographer: Skipped 185 frames! The application may be doing too much work on its main thread.
06-21 18:00:20.223 18668-18668/com.example.yoyojojo.appstream2 E/MediaPlayer: Error (100,0)
06-21 18:00:20.223 18668-18668/com.example.yoyojojo.appstream2 E/MediaPlayer: Error (100,0)
06-21 18:00:20.231 18668-18668/com.example.yoyojojo.appstream2 E/MediaPlayer: Error (-38,0)