用于录制文件输出,我使用MediaPlayer。 通常,当我点击按钮时,启动媒体文件。
但是,有时候不能发声。
/MediaPlayer: mediaplayer went away with unhandled events
W/MediaPlayer-JNI: MediaPlayer finalized without being released
起初我认为在语音文件完成之前,单击按钮会出现此问题。
但即使我反复按下按钮,有时也不能发声。
源。
player = new MediaPlayer();
player.reset();
player.setAudioStreamType(AudioManager.STREAM_MUSIC);
try {
player.reset();
AssetFileDescriptor assetFileDescriptor =
getApplicationContext().getResource().openRawResourceFd(R.raw.sound);
player.setDataSource(assetFileDescriptor.getFileDescriptor(),
assetFileDescriptor.getStartOffset(), assetFileDescriptor.getLength());
player.prepare();
player.start();
} catch (Exception e) {
e.printStackTrace();
}
player.setOnCompletionListener(new MediaPlayer.OnCompletionListener() {
@Override
public void onCompletion(MediaPlayer mediaPlayer) {
if (player != null) {
player.stop();
player.release();
}
}
});
单击按钮时,如何修复有时不发声的声音?
感谢。
答案 0 :(得分:0)
如果MediaPlayer.release()
再次使用,则没有理由致电reset()
,因为呼叫player = new MediaPlayer();
player.setAudioStreamType(AudioManager.STREAM_MUSIC);
player.setOnCompletionListener(new MediaPlayer.OnCompletionListener() {
@Override
public void onCompletion(MediaPlayer mediaPlayer) {
mediaPlayer.reset();
}
});
将释放所有内存和放大器。正在使用的编解码器。
INIT:
void onButtonClicked() {
player.reset();
AssetFileDescriptor assetFileDescriptor =
getApplicationContext().getResource().openRawResourceFd(R.raw.sound);
player.setDataSource(assetFileDescriptor.getFileDescriptor(),
assetFileDescriptor.getStartOffset(), assetFileDescriptor.getLength());
player.prepare();
player.start();
}
处理按钮点击次数:
Sub auto_updateTest()
Dim rng11 As Range, cell11 As Range
Dim rng12 As Range, cell12 As Range
Set rng11 = Range("E3:F4")
Set rng12 = Range("A3:B4")
For Each cell12 In rng12
For Each cell11 In rng11
cell11.Value = cell11.Value + cell12.Value
Next cell11
Next cell12
End Sub