我正在尝试使用RTP packets
在android中发送和接收audiostream
。我可以发送数据包。但是接收似乎不起作用,或者我缺少任何技巧。我已在清单文件中授予RECORD_AUDIO
权限。并在应用程序(设备)Settings -> Apps -> (Click the Gear) -> App Permissions -> Microphone
中对此进行了验证。我仍然听不到扬声器或麦克风的声音。
InetAddress inetAddress;
AudioGroup audioGroup = new AudioGroup();
MediaPlayer mediaPlayer = new MediaPlayer();
AudioStream audioStream;
AudioManager audioManager = (AudioManager) getSystemService(AUDIO_SERVICE);
audioManager.setMode(AudioManager.MODE_IN_COMMUNICATION);
audioManager.setSpeakerphoneOn(true);
audioGroup.setMode(AudioGroup.MODE_NORMAL);
inetAddress = InetAddress.getByName(getLocalIpAddress());
audioStream = new AudioStream(inetAddress);
audioStream.setCodec(AudioCodec.PCMU);
audioStream.setMode(RtpStream.MODE_NORMAL);
InetAddress inetAddressRemote = InetAddress.getByName(remoteIp);
audioStream.associate(inetAddressRemote, remotePort);
audioStream.join(audioGroup);
即使我提供了许可,我仍然在日志中遵循警告。
W/ServiceManager: Permission failure: android.permission.RECORD_AUDIO from uid=10080 pid=-1
E/AudioFlinger: openRecord() permission denied: recording not allowed
I/AudioFlinger: AudioFlinger's thread 0xb2418180 ready to run
E/AudioRecord: AudioFlinger could not create record track, status: -1
E/AudioGroup: cannot initialize audio device
这是我的gradle文件版本。
android {
compileSdkVersion 29
buildToolsVersion "29.0.0"
defaultConfig {
applicationId "appId"
minSdkVersion 21
targetSdkVersion 29
versionCode 1
versionName "1.0"
}
降低targetversion below 23
可以消除所有错误,但这是正确的方法吗?对rtpstream packets