manager.setSpeakerphoneOn(true);
适用于手机但不适用于平板电脑。 声音不会从扬声器播放。有人知道为什么吗? 请帮忙
在清单文件中还添加了MODIFY_AUDIO_SETTINGS权限。
我的代码
音频文件的路径 String mainpath =“android.resource://com.example.texttospeech/raw/”;
public void makeSound(String amount) {
AudioManager m_amAudioManager;
m_amAudioManager = (AudioManager)getSystemService(Context.AUDIO_SERVICE);
m_amAudioManager.setMode(AudioManager.MODE_CURRENT);
m_amAudioManager.setSpeakerphoneOn(true);
int numInput = Integer.parseInt(amount);
String amt = amount;
Log.d("The amount is : ", amt);
int length = amt.length();
Log.d("Length of the String : ", Integer.toString(length));
thousandsDigit = numInput / 1000;
ths = numInput % 1000;
hundredsDigit = ths / 100;
hs = ths % 100;
tensDigit = hs / 10;
onesDigit = hs % 10;
System.out.println(thousandsDigit);
System.out.println(hundredsDigit);
System.out.println(tensDigit);
System.out.println(onesDigit);
Log.d("Transaction type:",transactionType);
if (transactionType.equals("WITHDRAW")){
// withdraw();
final MediaPlayer mp11 = new MediaPlayer();
try {
mp11.setDataSource(AgentTransaction.this,
Uri.parse(mainpath + "withdraw"));
mp11.prepare();
} catch (IllegalArgumentException | SecurityException
| IllegalStateException | IOException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
mp11.start();
mp11.setOnCompletionListener(new MediaPlayer.OnCompletionListener() {
@Override
public void onCompletion(MediaPlayer mp) {
mp11.release();
}
});
}
}