我一直在使用 MarshMallow 上的MediaPlayer
播放音频文件时出现问题,因为它很快就停止了一段时间。
音频文件是 .wav 文件,长度不超过3秒。它具有以下属性:
我在以下设备上遇到过此问题:
相同的代码适用于以前版本的Android。
从最初看起来,由于NuPlayer
的实施和AwesomePlayer
的删除,它看起来很像。在 Lollipop 中,在开发人员设置中可选择使用NuPlayer
。
有没有人经历过这个?你做了什么来解决这个问题?
我的代码只需执行以下操作:
String mAudioFilePath = "path to audio file"
MediaPlayer player = new MediaPlayer();
player.setWakeMode(getActivity(), PowerManager.PARTIAL_WAKE_LOCK);
player.reset();
player.setDataSource(mAudioFilePath);
player.setOnPreparedListener(new MediaPlayer.OnPreparedListener() {
@Override
public void onPrepared(MediaPlayer mp) {
mp.start();
audioSeekBar.setProgress(0);
audioSeekBar.setMax(100);
updateProgressBar();
}
});
player.prepareAsync();
updateProgressBar()
- 更新audioSeekBar
并停止使用以下内容更新SeekBar
:
player.setOnCompletionListener(new MediaPlayer.OnCompletionListener() {
@Override
public void onCompletion(MediaPlayer mp) {
mHandler.removeCallbacks(mUpdateTimeTask);
audioSeekBar.setProgress(0);
audioSeekBar.setMax(100);
player.stop();
player.reset();
}
});
我得到以下堆栈跟踪:
05-01 18:53:18.344 31287-31287/? D/LockScreen: [ChargingTimeHelper] skip updating, mPreLevel: 71, curLevel: 71
05-01 18:53:23.582 7326-7441/? D/audio_hw_primary: out_set_parameters: enter: usecase(1: low-latency-playback) kvpairs: routing=2
05-01 18:53:23.593 7326-7441/? D/audio_hw_primary: start_output_stream: enter: stream(0xb5f77600)usecase(1: low-latency-playback) devices(0x2)
05-01 18:53:23.593 7326-7441/? D/audio_hw_primary: start_output_stream: enter: usecase(1: low-latency-playback) devices(0x2)
05-01 18:53:23.594 7326-7441/? D/audio_hw_primary: select_devices: out_snd_device(2: speaker) in_snd_device(0: )
05-01 18:53:23.594 7326-7441/? W/msm8974_platform: Codec backend bitwidth 16, samplerate 48000
05-01 18:53:23.594 7326-7441/? D/hardware_info: hw_info_append_hw_type : device_name = speaker
05-01 18:53:23.594 7326-7441/? I/msm8974_platform: platform_send_audio_calibration: sending audio calibration for snd_device(2) acdb_id(15)
05-01 18:53:23.594 7326-7441/? D/ACDB-LOADER: ACDB -> send_audio_cal, acdb_id = 15, path = 0
05-01 18:53:23.594 7326-7441/? D/ACDB-LOADER: ACDB -> send_adm_topology
05-01 18:53:23.594 7326-7441/? D/ACDB-LOADER: ACDB -> ACDB_CMD_GET_AUDPROC_COMMON_TOPOLOGY_ID
05-01 18:53:23.594 7326-7441/? D/ACDB-LOADER: ACDB -> send_asm_topology
05-01 18:53:23.594 7326-7441/? D/ACDB-LOADER: ACDB -> ACDB_CMD_GET_AUDPROC_STREAM_TOPOLOGY_ID
05-01 18:53:23.594 7326-7441/? D/ACDB-LOADER: ACDB -> send_audtable
05-01 18:53:23.594 7326-7441/? D/ACDB-LOADER: ACDB -> ACDB_CMD_GET_AUDPROC_COMMON_TABLE
05-01 18:53:23.594 7326-7441/? D/ACDB-LOADER: ACDB -> AUDIO_SET_AUDPROC_CAL
05-01 18:53:23.594 7326-7441/? D/ACDB-LOADER: ACDB -> send_audvoltable
05-01 18:53:23.594 7326-7441/? D/ACDB-LOADER: ACDB -> ACDB_CMD_GET_AUDPROC_GAIN_DEP_STEP_TABLE
[ 05-01 18:53:23.594 7326: 7441 D/ ]
Failed to fetch the lookup information of the device 0000000F
05-01 18:53:23.594 7326-7441/? E/ACDB-LOADER: Error: ACDB AudProc vol returned = -19
05-01 18:53:23.594 7326-7441/? D/ACDB-LOADER: ACDB -> AUDIO_SET_AUDPROC_VOL_CAL
05-01 18:53:23.594 7326-7441/? D/ACDB-LOADER: ACDB -> send_afe_cal
05-01 18:53:23.594 7326-7441/? D/ACDB-LOADER: ACDB -> ACDB_CMD_GET_AFE_COMMON_TABLE
[ 05-01 18:53:23.594 7326: 7441 D/ ]
Failed to fetch the lookup information of the device 0000000F
05-01 18:53:23.594 7326-7441/? E/ACDB-LOADER: Error: ACDB AFE returned = -19
05-01 18:53:23.594 7326-7441/? D/ACDB-LOADER: ACDB -> AUDIO_SET_AFE_CAL
05-01 18:53:23.601 7326-7441/? D/audio_hw_primary: select_devices: done
05-01 18:53:23.604 7326-7052/? I/FFmpegExtractor: android-source:0xaeaf9240
05-01 18:53:23.605 7326-7052/? D/FFmpegExtractor: suppoted codec(pcm_s16le) by official Stagefright
05-01 18:53:23.605 7326-7052/? D/FFmpegExtractor: ffmpeg detected media content as 'audio/x-wav' with confidence 0.08
05-01 18:53:23.607 7326-7051/? D/NuPlayerDriver: notifyListener_l(0xb5f26b60), (1, 0, 0)
05-01 18:53:23.611 7326-7447/? D/NuPlayerDriver: start(0xb5f26b60), state is 4, eos is 0
05-01 18:53:23.611 7326-7051/? I/GenericSource: start
05-01 18:53:23.612 7326-7051/? I/MetaData: srte: (int32_t) 8000
05-01 18:53:23.612 7326-7051/? I/MetaData: sbit: (int32_t) 16
05-01 18:53:23.612 7326-7051/? I/MetaData: pfmt: (int32_t) 1
05-01 18:53:23.612 7326-7051/? I/MetaData: mime: (char*) audio/raw
05-01 18:53:23.612 7326-7051/? I/MetaData: inpS: (int32_t) 32768
05-01 18:53:23.612 7326-7051/? I/MetaData: dura: (int64_t) 2950000
05-01 18:53:23.612 7326-7051/? I/MetaData: chnm: (int32_t) 0
05-01 18:53:23.612 7326-7051/? I/MetaData: #chn: (int32_t) 1
05-01 18:53:23.612 7326-7051/? I/AudioPolicyManagerCustom: PCM offload property is enabled
05-01 18:53:23.612 7326-7051/? I/AVNuUtils: No channel mask, try channel count
05-01 18:53:23.612 7326-7051/? W/AVNuUtils: No bitrate info
05-01 18:53:23.612 7326-7051/? I/NuPlayer: canOffloadDecodedPCMStream
05-01 18:53:23.612 7326-7051/? I/MetaData: srte: (int32_t) 8000
05-01 18:53:23.612 7326-7051/? I/MetaData: sbit: (int32_t) 16
05-01 18:53:23.612 7326-7051/? I/MetaData: mime: (char*) audio/raw
05-01 18:53:23.612 7326-7051/? I/MetaData: dura: (int64_t) 2950000
05-01 18:53:23.612 7326-7051/? I/MetaData: chnm: (int32_t) 1
05-01 18:53:23.612 7326-7051/? I/MetaData: #chn: (int32_t) 1
05-01 18:53:23.612 7326-7051/? I/AVNuUtils: decision 0 mime audio/raw
05-01 18:53:23.612 7326-7051/? I/MetaData: srte: (int32_t) 8000
05-01 18:53:23.612 7326-7051/? I/MetaData: sbit: (int32_t) 16
05-01 18:53:23.612 7326-7051/? I/MetaData: mime: (char*) audio/raw
05-01 18:53:23.612 7326-7051/? I/MetaData: dura: (int64_t) 2950000
05-01 18:53:23.612 7326-7051/? I/MetaData: chnm: (int32_t) 1
05-01 18:53:23.612 7326-7051/? I/MetaData: #chn: (int32_t) 1
05-01 18:53:23.613 7326-7051/? I/AudioPolicyManagerCustom: PCM offload property is enabled
05-01 18:53:23.613 7326-7051/? I/NuPlayer: PCM offload decided: 0
05-01 18:53:23.613 7326-7051/? I/MetaData: srte: (int32_t) 8000
05-01 18:53:23.613 7326-7051/? I/MetaData: sbit: (int32_t) 16
05-01 18:53:23.613 7326-7051/? I/MetaData: pfmt: (int32_t) 1
05-01 18:53:23.613 7326-7051/? I/MetaData: mime: (char*) audio/raw
05-01 18:53:23.613 7326-7051/? I/MetaData: inpS: (int32_t) 32768
05-01 18:53:23.613 7326-7051/? I/MetaData: dura: (int64_t) 2950000
05-01 18:53:23.613 7326-7051/? I/MetaData: chnm: (int32_t) 0
05-01 18:53:23.613 7326-7051/? I/MetaData: #chn: (int32_t) 1
05-01 18:53:23.614 7326-7051/? I/AudioPolicyManagerCustom: PCM offload property is enabled
05-01 18:53:23.614 7326-7051/? I/AVNuUtils: No channel mask, try channel count
05-01 18:53:23.614 7326-7051/? W/AVNuUtils: No bitrate info
05-01 18:53:23.614 7326-7051/? I/NuPlayer: canOffloadDecodedPCMStream
05-01 18:53:23.614 7326-7051/? I/MetaData: srte: (int32_t) 8000
05-01 18:53:23.614 7326-7051/? I/MetaData: sbit: (int32_t) 16
05-01 18:53:23.614 7326-7051/? I/MetaData: mime: (char*) audio/raw
05-01 18:53:23.614 7326-7051/? I/MetaData: dura: (int64_t) 2950000
05-01 18:53:23.614 7326-7051/? I/MetaData: chnm: (int32_t) 1
05-01 18:53:23.614 7326-7051/? I/MetaData: #chn: (int32_t) 1
05-01 18:53:23.614 7326-7051/? I/AVNuUtils: decision 0 mime audio/raw
05-01 18:53:23.614 7326-7051/? I/MetaData: srte: (int32_t) 8000
05-01 18:53:23.614 7326-7051/? I/MetaData: sbit: (int32_t) 16
05-01 18:53:23.615 7326-7051/? I/MetaData: mime: (char*) audio/raw
05-01 18:53:23.615 7326-7051/? I/MetaData: dura: (int64_t) 2950000
05-01 18:53:23.615 7326-7051/? I/MetaData: chnm: (int32_t) 1
05-01 18:53:23.615 7326-7051/? I/MetaData: #chn: (int32_t) 1
05-01 18:53:23.615 7326-7051/? I/AudioPolicyManagerCustom: PCM offload property is enabled
05-01 18:53:23.615 7326-7051/? I/NuPlayer: PCM offload decided: 0
05-01 18:53:23.621 7326-7055/? E/OMXNodeInstance: setConfig(53:google.raw.decoder, ConfigPriority(0x6f800002)) ERROR: Undefined(0x80001001)
05-01 18:53:23.621 7326-7055/? I/ACodec: codec does not support config priority (err -2147483648)
05-01 18:53:23.622 7326-7055/? I/MediaCodec: MediaCodec will operate in async mode
05-01 18:53:23.687 7326-7441/? D/audio_hw_primary: out_set_parameters: enter: usecase(1: low-latency-playback) kvpairs: routing=2
05-01 18:53:23.688 7326-7051/? D/NuPlayerDriver: notifyListener_l(0xb5f26b60), (6, 0, 0)
05-01 18:53:23.688 7326-7054/? I/NuPlayerDecoder: [audio] saw output EOS
05-01 18:53:24.314 5072-5286/? D/HeadsetStateMachine: Disconnected process message: 10, size: 0
05-01 18:53:24.315 31287-31287/? D/LockScreen: [BatteryInfoTracker] Received: android.intent.action.BATTERY_CHANGED
05-01 18:53:24.315 31287-31287/? D/LockScreen: [ChargingTimeHelper] update charging, scale: 100, mPreLevel: 71, curLevel: 71, mPreTime: 66930510, curTime: 67110512, plug: 2, mStatsStarted: true
05-01 18:53:24.315 31287-31287/? D/LockScreen: [ChargingTimeHelper] skip updating, mPreLevel: 71, curLevel: 71
05-01 18:53:25.440 7326-7053/? E/NuPlayerRenderer: CHECK_EQ(copy mAudioSink->frameSize(), 0) failed b/25372978
05-01 18:53:25.440 7326-7053/? E/NuPlayerRenderer: mAudioSink->frameSize() 2
05-01 18:53:25.440 7326-7053/? E/NuPlayerRenderer: bytes to copy 14431
05-01 18:53:25.440 7326-7053/? E/NuPlayerRenderer: entry size 14431, entry offset 0
05-01 18:53:25.440 7326-7051/? E/NuPlayer: audio track encountered an error (-2147483648)
05-01 18:53:25.440 7326-7051/? D/NuPlayerDriver: notifyListener_l(0xb5f26b60), (100, 1, -2147483648)
05-01 18:53:25.440 7326-7051/? D/NuPlayerDriver: notifyListener_l(0xb5f26b60), (2, 0, 0)
05-01 18:53:25.440 4711-4726/com.example.myapp E/MediaPlayer: error (1, -2147483648)
05-01 18:53:25.440 4711-4711/com.example.myapp E/MediaPlayer: Error (1,-2147483648)
05-01 18:53:25.442 7326-7447/? D/NuPlayerDriver: stop(0xb5f26b60)
05-01 18:53:25.442 7326-7447/? D/NuPlayerDriver: notifyListener_l(0xb5f26b60), (8, 0, 0)
05-01 18:53:25.442 7326-7448/? D/NuPlayerDriver: reset(0xb5f26b60)
05-01 18:53:25.446 7326-7051/? D/NuPlayerDriver: notifyResetComplete(0xb5f26b60)
05-01 18:53:25.447 7326-7326/? D/NuPlayerDriver: reset(0xb5f26b60)
05-01 18:53:28.446 7326-7441/? D/audio_hw_primary: out_standby: enter: stream (0xb5f77600) usecase(1: low-latency-playback)
非常感谢任何帮助