| | |
| | | import java.util.ArrayList; |
| | | import java.util.List; |
| | | |
| | | /** |
| | | * 音源说明: |
| | | * 1------------------------SD-CARD |
| | | * 2------------------------NAS-HDD |
| | | * 3------------------------SERVER //暂未用 |
| | | * 4------------------------WEB-RADIO //暂未用 |
| | | * 5------------------------RADIO |
| | | * 6------------------------AUDIO-IN |
| | | * 7------------------------INTERCOM //暂未用 |
| | | * 8------------------------ BLUETOOTH |
| | | * 9------------------------ S/PDIF //AUDIO_IN2 |
| | | */ |
| | | public class AudioActivity extends AppCompatActivity { |
| | | private Button getCurSongInfoBtn, playPauseBtn, playStopBtn, preSongBtn, nextSongBtn, volMinBtn, volMidBtn, volMaxBtn, modeBtn, nextListBtn, preListBtn; |
| | | private AppliancesInfo appliancesInfo; |
| | |
| | | private TextView curSongInfoTv, curSongNameTv; |
| | | private int curListNum;//由于不同厂商需求,必须自行记录当前的列表号 |
| | | private boolean isInit;//记录是否初始化 |
| | | private int SourceId = 1;//音源ID号 |
| | | |
| | | @Override |
| | | protected void onCreate(Bundle savedInstanceState) { |
| | |
| | | if (!EventBus.getDefault().isRegistered(this)) { |
| | | EventBus.getDefault().register(this); |
| | | } |
| | | |
| | | //设置音源号 |
| | | appliancesInfo.setIntCurState(SourceId); |
| | | |
| | | adapter = new ArrayAdapter<String>(AudioActivity.this, android.R.layout.simple_list_item_1, listString); |
| | | listView.setAdapter(adapter); |
| | | HDLCommand.audioCtrl(appliancesInfo, HDLAudio.GET_AUDIO_CURRRENT_INFO);//获取当前音乐信息。返回当前歌曲、所有信息。 |
| | |
| | | import com.hdl.sdk.hdl_core.HDLDeviceManger.EventBusEvent.ThirdPartyBgmInfoEvent; |
| | | import com.hdl.sdk.hdl_core.HDLDeviceManger.EventBusEvent.WarningInfoEvent; |
| | | import com.hdl.sdk.hdl_core.Util.NetUtil.NetWorkUtil; |
| | | import com.hdl.sdk.hdl_core.Util.TransformUtil.HDLUtlis; |
| | | import com.hdl.sdk.hdl_sdk.R; |
| | | import com.hdl.sdk.hdl_sdk.utlis.HDLLog; |
| | | |
| | |
| | | initView(); |
| | | setOnClick(); |
| | | |
| | | // String str = "#Z018TYPE0010,music121"; |
| | | // String result = str.substring(4, 5); |
| | | // HDLLog.I("result:"+result); |
| | | |
| | | // hideTestButton(); |
| | | |
| | | double AA = HDLUtlis.byteToDouble((byte)0, (byte)0, (byte)134, (byte) 160); |
| | | HDLLog.I("byteToDouble:"+AA); |
| | | } |
| | | |
| | | private void initView() { |
| | |
| | | EventBus.getDefault().post(new AudioInfoEvent(CALLBACK_CURRENT_VOLUME, 79 - (Integer.parseInt(volNum)), audioInfo)); |
| | | } else if (isExitData(arrMusicData[0], "TYPE")) { |
| | | Log.i("djl","Type ----> musicData = "+musicData); |
| | | byte[] musicBytes = audioGetListParse(curListNum, 1); |
| | | String sourceId = musicData.substring(4, 5); |
| | | byte[] musicBytes = audioGetListParse(curListNum, 1, sourceId); |
| | | sendAudioData(getDatas, musicBytes); |
| | | } else if (isExitData(arrMusicData[0], "LIST")) { |
| | | |
| | |
| | | } |
| | | int intNum = Integer.parseInt(num); |
| | | if (curListNum == intNum) {//判断回复的数据是否为当前列表数 |
| | | byte[] musicBytes = audioGetListParse(curListNum, 2); |
| | | String sourceId = musicData.substring(4, 5); |
| | | byte[] musicBytes = audioGetListParse(curListNum, 2, sourceId); |
| | | sendAudioData(getDatas, musicBytes); |
| | | } |
| | | } else if (isExitData(arrMusicData[0], "SONG")) { |
| | |
| | | strAsc += intAsc / 10; |
| | | strAsc += intAsc % 10; |
| | | } |
| | | String byteAsc = stringToAscii(strAsc); |
| | | String[] arrAsc = byteAsc.split(","); |
| | | int a1 = Integer.parseInt(arrAsc[0]); |
| | | int a2 = Integer.parseInt(arrAsc[1]); |
| | | return new byte[]{0x2A, 0x5A, 0x31, 0x56, 0x4F, 0x4C, (byte) a1, (byte) a2, 0x0D}; |
| | | // String byteAsc = stringToAscii(strAsc); |
| | | // String[] arrAsc = byteAsc.split(","); |
| | | // int a1 = Integer.parseInt(arrAsc[0]); |
| | | // int a2 = Integer.parseInt(arrAsc[1]); |
| | | // return new byte[]{0x2A, 0x5A, 0x31, 0x56, 0x4F, 0x4C, (byte) a1, (byte) a2, 0x0D}; |
| | | |
| | | byte[] musicBytes = StringUtil.GetMusicBytes("*Z1VOL" + strAsc); |
| | | return musicBytes; |
| | | } |
| | | } |
| | | |
| | | public static byte[] audioChooseSongParse(int value1, int value2) { |
| | | public static byte[] audioChooseSongParse(int value1, int value2, int sourceId) { |
| | | int listNum = value1; |
| | | int songNum = value2 + 1; |
| | | String songNumStrAsc = ""; |
| | |
| | | listNumStrAsc += listNum; |
| | | } |
| | | |
| | | String songNumByteAsc = stringToAscii(songNumStrAsc); |
| | | String listNumByteAsc = stringToAscii(listNumStrAsc); |
| | | |
| | | String[] songNumArrAsc = songNumByteAsc.split(","); |
| | | String[] listNumArrAsc = listNumByteAsc.split(","); |
| | | |
| | | int a1 = Integer.parseInt(songNumArrAsc[0]); |
| | | int a2 = Integer.parseInt(songNumArrAsc[1]); |
| | | int a3 = Integer.parseInt(songNumArrAsc[2]); |
| | | |
| | | int b1 = Integer.parseInt(listNumArrAsc[0]); |
| | | int b2 = Integer.parseInt(listNumArrAsc[1]); |
| | | int b3 = Integer.parseInt(listNumArrAsc[2]); |
| | | // String songNumByteAsc = stringToAscii(songNumStrAsc); |
| | | // String listNumByteAsc = stringToAscii(listNumStrAsc); |
| | | // |
| | | // String[] songNumArrAsc = songNumByteAsc.split(","); |
| | | // String[] listNumArrAsc = listNumByteAsc.split(","); |
| | | // |
| | | // int a1 = Integer.parseInt(songNumArrAsc[0]); |
| | | // int a2 = Integer.parseInt(songNumArrAsc[1]); |
| | | // int a3 = Integer.parseInt(songNumArrAsc[2]); |
| | | // |
| | | // int b1 = Integer.parseInt(listNumArrAsc[0]); |
| | | // int b2 = Integer.parseInt(listNumArrAsc[1]); |
| | | // int b3 = Integer.parseInt(listNumArrAsc[2]); |
| | | //*Z011SONG001 |
| | | return new byte[]{0x2A, 0x5A, 0x30, 0x31, 0x31, 0x53, 0x4F, 0x4E, 0x47, 0x30 |
| | | , 0x30, 0x31, (byte) b1, (byte) b2, (byte) b3, (byte) a1, (byte) a2, (byte) a3, 0x32, 0x0D}; |
| | | // return new byte[]{0x2A, 0x5A, 0x30, 0x31, 0x31, 0x53, 0x4F, 0x4E, 0x47, 0x30 |
| | | // , 0x30, 0x31, (byte) b1, (byte) b2, (byte) b3, (byte) a1, (byte) a2, (byte) a3, 0x32, 0x0D}; |
| | | |
| | | byte[] musicBytes = StringUtil.GetMusicBytes("*Z01" + sourceId+ "SONG" +listNumStrAsc + songNumStrAsc + "2"); |
| | | return musicBytes; |
| | | } |
| | | |
| | | private static byte[] audioGetListParse(int num, int type) { |
| | | private static byte[] audioGetListParse(int num, int type, String sourceId) { |
| | | String strAsc = ""; |
| | | if (num < 10) { |
| | | strAsc = "00" + num; |
| | |
| | | int a2 = Integer.parseInt(arrAsc[1]); |
| | | int a3 = Integer.parseInt(arrAsc[2]); |
| | | if (type == 1) { |
| | | return new byte[]{0x2A, 0x5A, 0x30, 0x31, 0x31, 0x4C, 0x49, 0x53, |
| | | 0x54, 0x30, 0x30, 0x31, (byte) a1, (byte) a2, (byte) a3, 0x31, 0x0D}; |
| | | // return new byte[]{0x2A, 0x5A, 0x30, 0x31, 0x31, 0x4C, 0x49, 0x53, |
| | | // 0x54, 0x30, 0x30, 0x31, (byte) a1, (byte) a2, (byte) a3, 0x31, 0x0D}; |
| | | byte[] musicBytes = StringUtil.GetMusicBytes("*Z01" + sourceId + "LIST001" + strAsc + "1"); |
| | | return musicBytes; |
| | | |
| | | } else { |
| | | return new byte[]{42, 90, 48, 49, 49, 83, 79, 78, 71, 48, 48, 49, (byte) a1, (byte) a2, (byte) a3, 48, 48, 49, 49, 13}; |
| | | // return new byte[]{0x2A, 0x5A, 0x30, 0x31, 0x31, 0x53, 0x4F, 0x4E, 0x47, 0x30, 0x30, 0x31, (byte) a1, (byte) a2, (byte) a3, 0x30, 0x30, 0x31, 0x31, 0x0D}; |
| | | byte[] musicBytes = StringUtil.GetMusicBytes("*Z01" + sourceId + "SONG001" + strAsc + "0011"); |
| | | return musicBytes; |
| | | } |
| | | } |
| | | } |
| | |
| | | import com.hdl.sdk.hdl_core.Util.NetUtil.NetWorkUtil; |
| | | import com.hdl.sdk.hdl_core.Util.SPUtil.SPUtils; |
| | | import com.hdl.sdk.hdl_core.Util.TransformUtil.HDLUtlis; |
| | | import com.hdl.sdk.hdl_core.Util.TransformUtil.StringUtil; |
| | | |
| | | import org.greenrobot.eventbus.EventBus; |
| | | |
| | |
| | | public static void audioCtrl(AppliancesInfo info, int type) { |
| | | byte[] musicBytes; |
| | | int command; |
| | | int sourceId = info.getIntCurState(); |
| | | switch (type) { |
| | | case HDLAudio.SET_AUDIO_PLAYSTOP: |
| | | command = Configuration.AUDIO_CTRL_READ_COMMAND; |
| | | musicBytes = new byte[]{0x2A, 0x53, 0x31, 0x50, 0x4C, 0x41, 0x59, 0x53, 0x54, 0x4F, 0x50, 0x0D}; |
| | | // musicBytes = new byte[]{0x2A, 0x53, 0x31, 0x50, 0x4C, 0x41, 0x59, 0x53, 0x54, 0x4F, 0x50, 0x0D}; |
| | | musicBytes = StringUtil.GetMusicBytes("*S" +sourceId + "PLAYSTOP"); |
| | | break; |
| | | case HDLAudio.SET_AUDIO_PLAYPAUSE: |
| | | command = Configuration.AUDIO_CTRL_READ_COMMAND; |
| | | musicBytes = new byte[]{42, 83, 49, 80, 76, 65, 89, 80, 65, 85, 83, 69, 0x0D}; |
| | | // musicBytes = new byte[]{0x2A, 0x53, 0x31, 0x50, 0x4C, 0x41, 0x59, 0x50, 0x41, 0x55, 0x53, 0x45, 0x0D}; |
| | | musicBytes = StringUtil.GetMusicBytes("*S" +sourceId + "PLAYPAUSE"); |
| | | break; |
| | | case HDLAudio.SET_NEXT_SONG: |
| | | command = Configuration.AUDIO_CTRL_READ_COMMAND; |
| | | musicBytes = new byte[]{0x2A, 0x53, 0x31, 0x4E, 0x45, 0x58, 0x54, 0x0D}; |
| | | // musicBytes = new byte[]{0x2A, 0x53, 0x31, 0x4E, 0x45, 0x58, 0x54, 0x0D}; |
| | | musicBytes = StringUtil.GetMusicBytes("*S" +sourceId + "NEXT"); |
| | | break; |
| | | case HDLAudio.SET_PRE_SONG: |
| | | command = Configuration.AUDIO_CTRL_READ_COMMAND; |
| | | musicBytes = new byte[]{0x2A, 0x53, 0x31, 0x50, 0x52, 0x45, 0x56, 0x0D}; |
| | | // musicBytes = new byte[]{0x2A, 0x53, 0x31, 0x50, 0x52, 0x45, 0x56, 0x0D}; |
| | | musicBytes = StringUtil.GetMusicBytes("*S" +sourceId + "PREV"); |
| | | break; |
| | | case HDLAudio.GET_AUDIO_MODE: |
| | | command = Configuration.AUDIO_CTRL_READ_COMMAND; |
| | | musicBytes = new byte[]{0x2A, 0x53, 0x31, 0x50, 0x4C, 0x41, 0x59, 0x4D, 0x4F, 0x44, 0x45, 0x3F, 0x0D}; |
| | | // musicBytes = new byte[]{0x2A, 0x53, 0x31, 0x50, 0x4C, 0x41, 0x59, 0x4D, 0x4F, 0x44, 0x45, 0x3F, 0x0D}; |
| | | musicBytes = StringUtil.GetMusicBytes("*S" +sourceId + "PLAYMODE?"); |
| | | break; |
| | | case HDLAudio.SET_AUDIO_MODE_UP: |
| | | command = Configuration.AUDIO_CTRL_READ_COMMAND; |
| | | musicBytes = new byte[]{0x2A, 0x53, 0x31, 0x4D, 0x4F, 0x44, 0x45, 0x2B, 0x0D}; |
| | | // musicBytes = new byte[]{0x2A, 0x53, 0x31, 0x4D, 0x4F, 0x44, 0x45, 0x2B, 0x0D}; |
| | | musicBytes = StringUtil.GetMusicBytes("*S" +sourceId + "MODE+"); |
| | | break; |
| | | case HDLAudio.SET_AUDIO_MODE_DOWN: |
| | | command = Configuration.AUDIO_CTRL_READ_COMMAND; |
| | | musicBytes = new byte[]{0x2A, 0x53, 0x31, 0x4D, 0x4F, 0x44, 0x45, 0x2D, 0x0D}; |
| | | // musicBytes = new byte[]{0x2A, 0x53, 0x31, 0x4D, 0x4F, 0x44, 0x45, 0x2D, 0x0D}; |
| | | musicBytes = StringUtil.GetMusicBytes("*S" +sourceId + "MODE-"); |
| | | break; |
| | | case HDLAudio.GET_AUDIO_CURRRENT_INFO: |
| | | command = Configuration.AUDIO_CTRL_READ_COMMAND; |
| | | //*Z1STAUS?归为键 |
| | | musicBytes = new byte[]{0x2A, 0x5A, 0x31, 0x53, 0x54, 0x41, 0x54, 0x55, 0x53, 0x3F, 0x0D}; |
| | | // musicBytes = new byte[]{0x2A, 0x5A, 0x31, 0x53, 0x54, 0x41, 0x54, 0x55, 0x53, 0x3F, 0x0D}; |
| | | musicBytes = StringUtil.GetMusicBytes("*S" +sourceId + "STATUS?"); |
| | | break; |
| | | case HDLAudio.SET_PRE_LIST: |
| | | HDLAudio.isSetPreNextList = true; |
| | | command = Configuration.AUDIO_CTRL_READ_COMMAND; |
| | | musicBytes = new byte[]{0x2A, 0x53, 0x31, 0x50, 0x52, 0x45, 0x56, 0x4C, 0x49, 0x53, 0x54, 0x0D}; |
| | | // musicBytes = new byte[]{0x2A, 0x53, 0x31, 0x50, 0x52, 0x45, 0x56, 0x4C, 0x49, 0x53, 0x54, 0x0D}; |
| | | musicBytes = StringUtil.GetMusicBytes("*S" +sourceId + "PREVLIST"); |
| | | break; |
| | | case HDLAudio.SET_NEXT_LIST: |
| | | HDLAudio.isSetPreNextList = true; |
| | | command = Configuration.AUDIO_CTRL_READ_COMMAND; |
| | | musicBytes = new byte[]{0x2A, 0x53, 0x31, 0x4E, 0x45, 0x58, 0x54, 0x4C, 0x49, 0x53, 0x54, 0x0D}; |
| | | // musicBytes = new byte[]{0x2A, 0x53, 0x31, 0x4E, 0x45, 0x58, 0x54, 0x4C, 0x49, 0x53, 0x54, 0x0D}; |
| | | musicBytes = StringUtil.GetMusicBytes("*S" +sourceId + "NEXTLIST"); |
| | | break; |
| | | case HDLAudio.TEXT: |
| | | command = Configuration.AUDIO_MenuPlay_INSTRUCTION_COMMAND; |
| | | musicBytes = new byte[]{0x2A, 0x5A, 0x30, 0x31, 0x31, 0x4C, 0x49, 0x53, 0x54, 0x30, 0x30, 0x31, 0x30, 0x30, 0x32, 0x31, 0x0D}; |
| | | // musicBytes = new byte[]{0x2A, 0x5A, 0x30, 0x31, 0x31, 0x4C, 0x49, 0x53, 0x54, 0x30, 0x30, 0x31, 0x30, 0x30, 0x32, 0x31, 0x0D}; |
| | | musicBytes = StringUtil.GetMusicBytes("*Z01" +sourceId + "LIST0010021"); |
| | | break; |
| | | default: |
| | | command = 0; |
| | |
| | | public static void audioCtrl(AppliancesInfo info, int type, int value) { |
| | | byte[] musicBytes; |
| | | int command; |
| | | int sourceId = info.getIntCurState(); |
| | | switch (type) { |
| | | case HDLAudio.GET_AUDIO_LIST: |
| | | HDLAudio.numStr.clear(); |
| | |
| | | HDLAudio.curListNum = value; |
| | | command = Configuration.AUDIO_MenuPlay_INSTRUCTION_COMMAND; |
| | | //*Z011TYPE0011归位键 |
| | | musicBytes = new byte[]{0x2A, 0x5A, 0x30, 0x31, 0x31, 0x54, 0x59, 0x50, 0x45, 0x30, 0x30, 0x31, 0x31, 0x0D}; |
| | | // musicBytes = new byte[]{0x2A, 0x5A, 0x30, 0x31, 0x31, 0x54, 0x59, 0x50, 0x45, 0x30, 0x30, 0x31, 0x31, 0x0D}; |
| | | musicBytes = StringUtil.GetMusicBytes("*Z01" + sourceId + "TYPE0011"); |
| | | break; |
| | | case HDLAudio.SET_AUDIO_VOL: |
| | | command = Configuration.AUDIO_CTRL_READ_COMMAND; |
| | |
| | | public static void audioCtrl(AppliancesInfo info, int type, int listId, int songId) { |
| | | byte[] musicBytes; |
| | | int command; |
| | | int sourceId = info.getIntCurState(); |
| | | switch (type) { |
| | | |
| | | case HDLAudio.SET_CHOOSE_PLAY_SONG: |
| | | command = Configuration.AUDIO_MenuPlay_INSTRUCTION_COMMAND; |
| | | musicBytes = HDLAudio.audioChooseSongParse(listId, songId); |
| | | musicBytes = HDLAudio.audioChooseSongParse(listId, songId, sourceId); |
| | | break; |
| | | default: |
| | | command = 0; |
| | |
| | | * @param getDatas |
| | | */ |
| | | private static void handleAudioData(UdpDataBean getDatas) { |
| | | // HDLLog.info("处理HDL音乐协议"); |
| | | outter: |
| | | for (int i = 0, len = devicesDataList.size(); i < len; i++) { |
| | | if (devicesDataList.get(i).getSourceSubnetID() == getDatas.sourceSubnetID |
| | |
| | | for (int j = 0, len2 = infos.size(); j < len2; j++) { |
| | | if (infos.get(j).getBigType() == Configuration.AUDIO_BIG_TYPE) { |
| | | //暂时只支持旧版背景音乐 |
| | | if (infos.get(j).getDeviceType() == HDLApConfig.TYPE_MUSIC_MODULE) { |
| | | if (infos.get(j).getDeviceType() == HDLApConfig.TYPE_MUSIC_MODULE || infos.get(j).getDeviceType() == HDLApConfig.TYPE_MUSIC_NEW_MODULE) { |
| | | HDLAudio.parseAudioData(getDatas, infos.get(j)); |
| | | } |
| | | break outter; |
| | |
| | | /** |
| | | * Created by djl on 2017/3/17. |
| | | */ |
| | | |
| | | public class HDLUdpCore { |
| | | // private static MulticastSocket msr6000 = null; |
| | | // private static MulticastSocket msr6008 = null; |
| | |
| | | case 1: |
| | | isWant = true; |
| | | break; |
| | | case 2: |
| | | isWant = true; |
| | | break; |
| | | case 3: |
| | | isWant = true; |
| | | break; |
| | | case 7: |
| | | isWant = true; |
| | | break; |
| | |
| | | break; |
| | | case 2: |
| | | appliancesInfo.setDeviceName("逻辑灯控制"); |
| | | appliancesInfo.setDeviceType(HDLApConfig.TYPE_LIGHT_CCT); |
| | | break; |
| | | case 3: |
| | | appliancesInfo.setDeviceName("逻辑灯RGB"); |
| | | appliancesInfo.setDeviceType(HDLApConfig.TYPE_LIGHT_RGB); |
| | | break; |
| | | case 4: |
| | | appliancesInfo.setDeviceName("逻辑灯RGBW"); |
| | |
| | | appliancesInfo.setPort(port); |
| | | appliancesInfo.setIpAddress(ipAddress); |
| | | |
| | | if(littleType == 7 || littleType == 8){ |
| | | if(littleType == 2 ||littleType == 3 ||littleType == 7 || littleType == 8){ |
| | | appliancesInfo.setCtrlCommand(Configuration.LIGHT_RGB_CTRL_COMMAND); |
| | | appliancesInfo.setCtrlBackCommand(Configuration.LIGHT_RGB_CTRL_BACK_COMMAND); |
| | | appliancesInfo.setStateCommand(Configuration.LIGHT_RGB_STATE_COMMAND); |
| | |
| | | return byteArrayToFloat(mByte); |
| | | } |
| | | |
| | | |
| | | public static double byteToDouble(byte b1, byte b2, byte b3, byte b4) { |
| | | return b1 * 256 * 256 * 256 + b2 * 256 * 256 + b3 * 256 + b4; |
| | | } |
| | | |
| | | |
| | | /** |
| | | * byte[4]数组 转换为float类型 |
| | | * |
| | |
| | | + (byte) ((b >> 1) & 0x1) + (byte) ((b >> 0) & 0x1); |
| | | } |
| | | |
| | | |
| | | /** |
| | | * 音乐命令变成byte数组 |
| | | * @param commandString |
| | | * @return |
| | | */ |
| | | public static byte [] GetMusicBytes (String commandString){ |
| | | byte [] bytes = new byte[0]; |
| | | try { |
| | | bytes = commandString.getBytes("US-ASCII"); |
| | | byte [] sendBytes = new byte [bytes.length + 1]; |
| | | sendBytes [bytes.length] = 0x0D; |
| | | System.arraycopy (bytes, 0, sendBytes, 0, bytes.length); |
| | | return sendBytes; |
| | | } catch (UnsupportedEncodingException e) { |
| | | e.printStackTrace(); |
| | | return bytes; |
| | | } |
| | | } |
| | | |
| | | |
| | | // private byte[] formatStyleHDLResponse(String responsePart1, String responsePart2, int maxLen) throws UnsupportedEncodingException { |