尝试在其他Android设备上接收音频流时遇到问题
- 我有两个安卓手机,其中一个应该通过rtp发送声音,另一个应该收到它
这是发件人代码
package com.mywork.johnathan.zoomsenderapk;
import android.content.Intent;
import android.net.wifi.WifiInfo;
import android.net.wifi.WifiManager;
import android.provider.MediaStore;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import java.io.IOException;
import java.net.InetAddress;
import java.net.NetworkInterface;
import java.net.SocketException;
import java.util.Enumeration;
import android.app.Activity;
import android.content.Context;
import android.media.AudioManager;
import android.net.rtp.AudioCodec;
import android.net.rtp.AudioGroup;
import android.net.rtp.AudioStream;
import android.net.rtp.RtpStream;
import android.os.StrictMode;
import android.text.format.Formatter;
import android.util.Log;
import android.view.View;
import android.widget.Button;
import android.media.MediaPlayer;
public class MainActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
StrictMode.ThreadPolicy policy = new StrictMode.ThreadPolicy.Builder().permitAll().build();
StrictMode.setThreadPolicy(policy);
try {
AudioManager audio = (AudioManager) getSystemService(Context.AUDIO_SERVICE);
audio.setMode(AudioManager.MODE_NORMAL);
AudioGroup audioGroup = new AudioGroup();
audioGroup.setMode(AudioGroup.MODE_NORMAL);
AudioStream AudioStream = new AudioStream(InetAddress.getByName(getLocalIpAddress()));
AudioStream.setCodec(AudioCodec.PCMU);
AudioStream.setMode(RtpStream.MODE_SEND_ONLY);
//set receiver(vlc player) machine ip address(please update with your machine ip)
AudioStream.associate(InetAddress.getByName("192.168.1.3"),123);
AudioStream.join(audioGroup);
Log.e("pass",getLocalIpAddress().toString());
} catch (Exception e) {
Log.e("----------------------", e.toString());
e.printStackTrace();
}
}
public String getLocalIpAddress()
{
WifiManager wifiMgr = (WifiManager)getApplicationContext().getSystemService(WIFI_SERVICE);
WifiInfo wifiInfo = wifiMgr.getConnectionInfo();
int ip = wifiInfo.getIpAddress();
Log.e("-----------ip", Formatter.formatIpAddress(ip));
return Formatter.formatIpAddress(ip);
}
}
但我不知道我的接收器应用程序代码应该是什么
我猜诀窍就在这一行
AudioStream.setMode(RtpStream.MODE_SEND_ONLY);
在此先感谢♥
答案 0 :(得分:0)
您尝试了吗?
RtpStream.MODE_RECEIVE_ONLY
浏览RtpStream类的定义,您可以在其中找到所有选项。