I have a spinner set up with a list of songs and I'm trying to get the media player to play a song depending on which one has been chosen. I have set up the selected song as a variable but the mediaplayer is not seeing it. "R.raw.txt" is not seeing the string for some reason.
Button b = (Button) findViewById(R.id.toggleButton);
b.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Spinner spinner = (Spinner)findViewById(R.id.spinner);
String text = spinner.getSelectedItem().toString();
if (mp == null) {
mp = MediaPlayer.create(MainActivity.this, R.raw.text);
mp.start();
} else {
mp.stop();
mp = null;
}
}
});
在创建媒体播放器时,请尝试使用R.raw.txt而不是R.raw.text。
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.