嗨,我想在我的应用程序中实现收音机……我写了这段代码,它在模拟器 YouWave 中工作,但我在智能手机和另一台平板电脑上不工作,我不知道为什么..你能帮帮我吗?
这是收音机的代码:
public class radio extends Activity {
MediaPlayer media;
Button buttonplay;
Button buttonStopRecord;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.radio);
buttonStopRecord = (Button) findViewById(R.id.Stop);
buttonStopRecord.getBackground().setAlpha(150);
buttonStopRecord.setEnabled(false);
buttonStopRecord.setOnClickListener(new OnClickListener()
{
@Override
public void onClick(View view) {
if ( media.isPlaying() ) {
media.stop();
}
}
});
buttonplay = (Button) findViewById(R.id.play);
buttonplay.getBackground().setAlpha(150);
buttonplay.setOnClickListener(new OnClickListener()
{
@Override
public void onClick(View view) {
try
{
media = new MediaPlayer();
media.setAudioStreamType(AudioManager.USE_DEFAULT_STREAM_TYPE);
media.setDataSource("http://indiespectrum.com:9000");
media.prepare();
media.start();
if ( media.isPlaying()) {
buttonplay.setEnabled(false);
buttonStopRecord.setEnabled(true);
}
}
catch(Exception e)
{
//Getting Exception
}
}
});
Button accueil=(Button)findViewById(R.id.accueilr);
accueil.getBackground().setAlpha(200);
accueil.getBackground().setAlpha(150);
accueil.setOnClickListener(new OnClickListener()
{
@Override
public void onClick(View view) {
try{
if ( media.isPlaying() ) {
media.stop();
}
}catch (Exception e)
{
Intent i=new Intent(radio.this,main.class);
startActivity(i);
}
Intent i=new Intent(radio.this,main.class);
startActivity(i);
}
});
}
}