Java 媒体录音机的声音质量很差
我尝试做的是在上传到firebase后录制声音 然后回到我的视野中,我可以控制 播放/停止和进度。比如whatsApp音频信息 该类音频播放器通过按a键调用其主要活动 按钮并返回值,以便在firebase中上载文件 但是音质很差,而且只能在浏览器或浏览器中使用 直接在源文件夹中播放,否则我无法以其他格式播放,如 当我直接在源文件夹中播放时,使用三个GPP 遵循方法是主要活动Java 媒体录音机的声音质量很差,java,android,firebase,avaudioplayer,android-mediarecorder,Java,Android,Firebase,Avaudioplayer,Android Mediarecorder,我尝试做的是在上传到firebase后录制声音 然后回到我的视野中,我可以控制 播放/停止和进度。比如whatsApp音频信息 该类音频播放器通过按a键调用其主要活动 按钮并返回值,以便在firebase中上载文件 但是音质很差,而且只能在浏览器或浏览器中使用 直接在源文件夹中播放,否则我无法以其他格式播放,如 当我直接在源文件夹中播放时,使用三个GPP 遵循方法是主要活动 @Override public void onRecordingCompleted() { Log.i(TAG,
@Override
public void onRecordingCompleted() {
Log.i(TAG, "---------completed");
startThread = new Thread(new StartRecordMessage(myAudioRecorder));
startThread.start();
startRecordMessage = new StartRecordMessage(myAudioRecorder);
audioMessage = startRecordMessage.startRecording();
Log.i(TAG, "recordingCompleted--------------" + audioMessage);
UploadSound(audioMessage);
}
messageListAdapter.notifyDataSetChanged();
}
音频播放类
public class AudioPlayer {
public static void play(Context ctx, String path) {
try {
final AudioManager audioManager = (AudioManager) ctx.getSystemService(Context.AUDIO_SERVICE);
final int currentVolume = audioManager.getStreamVolume(AudioManager.STREAM_MUSIC);
final MediaPlayer mediaPlayer = MediaPlayer.create(ctx, Uri.parse(path));
mediaPlayer.setOnCompletionListener(new MediaPlayer.OnCompletionListener() {
@Override
public void onCompletion(MediaPlayer mp) {
if (!audioManager.isWiredHeadsetOn()) {
audioManager.setStreamVolume(AudioManager.STREAM_MUSIC, currentVolume, AudioManager.FLAG_VIBRATE);
}
mp.release();
}
});
mediaPlayer.setOnPreparedListener(new MediaPlayer.OnPreparedListener() {
@Override
public void onPrepared(MediaPlayer mp) {
if (!audioManager.isWiredHeadsetOn()) {
int volume = audioManager.getStreamMaxVolume(AudioManager.STREAM_MUSIC) / 2;
audioManager.setStreamVolume(AudioManager.STREAM_MUSIC, volume, AudioManager.FLAG_VIBRATE);
}
mp.start();
}
});
} catch(
Throwable e)
{
Log.i("AudioUtil", "Unable to play: " + path, e);
}
}
}
适配器类
holder.playStop.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
clickCount++;
if (clickCount==1) {
isPlayng=true;
holder.playStop.setBackgroundResource(R.drawable.ic_pause);
Log.i(TAG,"audio url---------------" + audio);
audioPlayer = new AudioPlayer();
audioPlayer.play(context,audio);
Log.i(TAG, "Media player ------------"+ clickCount + " is play: " +isPlayng);
}
if (clickCount>1){
isPlayng=false;
clickCount=0;
holder.playStop.setBackgroundResource(R.drawable.ic_play);
Log.i(TAG, "Media player ------------" + clickCount + " is play: " + isPlayng);
}
}
});
当我想要播放声音时,会触发跟随错误。班级
音频播放器类在适配器类中调用,但问题是
网址
。
2020-11-12 22:59:44.739 2621-2621 I/AudioUtil:无法播放:。
java.lang.NullPointerException:尝试调用虚拟方法“java.lang.Object”
空值上的android.content.Context.getSystemService(java.lang.String)“”
对象引用
在com.example….ChatRecord.AudioPlayer.play(AudioPlayer.java:13)
位于com.example.chatMapOriginal.Profile.Chat.MyGroups.GroupChatAdapter$1.onClick(GroupChatAdapter.java:137)
在android.view.view.performClick上(view.java:7192)
在android.view.view.performClickInternal(view.java:7166)
在android.view.view.access$3500(view.java:824)
在android.view.view$PerformClick.run(view.java:27592)
位于android.os.Handler.handleCallback(Handler.java:888)
位于android.os.Handler.dispatchMessage(Handler.java:100)
位于android.os.Looper.loop(Looper.java:213)
位于android.app.ActivityThread.main(ActivityThread.java:8178)
位于java.lang.reflect.Method.invoke(本机方法)
位于com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:513)
位于com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1101)
尝试在媒体文件中添加值 埃克斯梅普
// Setup values for the media file
ContentValues values = new ContentValues(4);
long current = System.currentTimeMillis();
values.put(MediaStore.Audio.Media.TITLE, "audio file");
values.put(MediaStore.Audio.Media.DATE_ADDED, (int) (current / 1000));
values.put(MediaStore.Audio.Media.MIME_TYPE, "audio/3gpp");
values.put(MediaStore.Audio.Media.DATA, audiofile.getAbsolutePath());
ContentResolver contentResolver = getContentResolver();
// Construct uris
Uri base = MediaStore.Audio.Media.EXTERNAL_CONTENT_URI;
Uri newUri = contentResolver.insert(base, values);
// Trigger broadcast to add
sendBroadcast(new Intent(Intent.ACTION_MEDIA_SCANNER_SCAN_FILE, newUri));
Toast.makeText(this, "Added File " + newUri, Toast.LENGTH_LONG).show();
此代码来自请不要在文本中使用强调/引用模式
// Setup values for the media file
ContentValues values = new ContentValues(4);
long current = System.currentTimeMillis();
values.put(MediaStore.Audio.Media.TITLE, "audio file");
values.put(MediaStore.Audio.Media.DATE_ADDED, (int) (current / 1000));
values.put(MediaStore.Audio.Media.MIME_TYPE, "audio/3gpp");
values.put(MediaStore.Audio.Media.DATA, audiofile.getAbsolutePath());
ContentResolver contentResolver = getContentResolver();
// Construct uris
Uri base = MediaStore.Audio.Media.EXTERNAL_CONTENT_URI;
Uri newUri = contentResolver.insert(base, values);
// Trigger broadcast to add
sendBroadcast(new Intent(Intent.ACTION_MEDIA_SCANNER_SCAN_FILE, newUri));
Toast.makeText(this, "Added File " + newUri, Toast.LENGTH_LONG).show();