Commit a4ab9a0a6cd22b11b52200b66c0417d9379e3960
1 parent
2b1e5697
集成rtc播放器
Showing
6 changed files
with
145 additions
and
19 deletions
Too many changes to show.
To preserve performance only 6 of 7 files are displayed.
src/main/java/com/genersoft/iot/vmp/common/StreamInfo.java
| ... | ... | @@ -18,6 +18,7 @@ public class StreamInfo { |
| 18 | 18 | private String ws_ts; |
| 19 | 19 | private String rtmp; |
| 20 | 20 | private String rtsp; |
| 21 | + private String rtc; | |
| 21 | 22 | private JSONArray tracks; |
| 22 | 23 | |
| 23 | 24 | public String getApp() { |
| ... | ... | @@ -139,4 +140,12 @@ public class StreamInfo { |
| 139 | 140 | public void setStreamId(String streamId) { |
| 140 | 141 | this.streamId = streamId; |
| 141 | 142 | } |
| 143 | + | |
| 144 | + public String getRtc() { | |
| 145 | + return rtc; | |
| 146 | + } | |
| 147 | + | |
| 148 | + public void setRtc(String rtc) { | |
| 149 | + this.rtc = rtc; | |
| 150 | + } | |
| 142 | 151 | } | ... | ... |
src/main/java/com/genersoft/iot/vmp/media/zlm/ZLMHttpHookListener.java
| ... | ... | @@ -4,6 +4,7 @@ import java.util.List; |
| 4 | 4 | import java.util.UUID; |
| 5 | 5 | |
| 6 | 6 | import com.alibaba.fastjson.JSON; |
| 7 | +import com.alibaba.fastjson.JSONArray; | |
| 7 | 8 | import com.genersoft.iot.vmp.common.StreamInfo; |
| 8 | 9 | import com.genersoft.iot.vmp.conf.MediaServerConfig; |
| 9 | 10 | import com.genersoft.iot.vmp.gb28181.bean.Device; |
| ... | ... | @@ -239,26 +240,33 @@ public class ZLMHttpHookListener { |
| 239 | 240 | String app = json.getString("app"); |
| 240 | 241 | String streamId = json.getString("stream"); |
| 241 | 242 | String schema = json.getString("schema"); |
| 242 | - boolean regist = json.getBoolean("regist"); | |
| 243 | + JSONArray tracks = json.getJSONArray("tracks"); | |
| 244 | + String regist = json.getString("regist"); | |
| 245 | + if (tracks != null) { | |
| 246 | + System.out.println("222222" + schema); | |
| 247 | + } | |
| 248 | + if ("rtmp".equals(schema)){ | |
| 243 | 249 | |
| 244 | - if ("rtp".equals(app) && !regist ) { | |
| 245 | - StreamInfo streamInfo = redisCatchStorage.queryPlayByStreamId(streamId); | |
| 246 | - if (streamInfo!=null){ | |
| 247 | - redisCatchStorage.stopPlay(streamInfo); | |
| 248 | - storager.stopPlay(streamInfo.getDeviceID(), streamInfo.getChannelId()); | |
| 249 | - }else{ | |
| 250 | - streamInfo = redisCatchStorage.queryPlaybackByStreamId(streamId); | |
| 251 | - redisCatchStorage.stopPlayback(streamInfo); | |
| 252 | - } | |
| 253 | - }else { | |
| 254 | - if (!"rtp".equals(app) && "rtmp".equals(schema)){ | |
| 255 | - if (regist) { | |
| 256 | - zlmMediaListManager.addMedia(app, streamId); | |
| 257 | - }else { | |
| 258 | - zlmMediaListManager.removeMedia(app, streamId); | |
| 250 | + if ("rtp".equals(app) && regist != null ) { | |
| 251 | + StreamInfo streamInfo = redisCatchStorage.queryPlayByStreamId(streamId); | |
| 252 | + if (streamInfo!=null){ | |
| 253 | + redisCatchStorage.stopPlay(streamInfo); | |
| 254 | + storager.stopPlay(streamInfo.getDeviceID(), streamInfo.getChannelId()); | |
| 255 | + }else{ | |
| 256 | + streamInfo = redisCatchStorage.queryPlaybackByStreamId(streamId); | |
| 257 | + redisCatchStorage.stopPlayback(streamInfo); | |
| 258 | + } | |
| 259 | + }else { | |
| 260 | + if (!"rtp".equals(app) ){ | |
| 261 | + if (regist == null) { | |
| 262 | + zlmMediaListManager.addMedia(app, streamId); | |
| 263 | + }else { | |
| 264 | + zlmMediaListManager.removeMedia(app, streamId); | |
| 265 | + } | |
| 259 | 266 | } |
| 260 | 267 | } |
| 261 | 268 | } |
| 269 | + | |
| 262 | 270 | JSONObject ret = new JSONObject(); |
| 263 | 271 | ret.put("code", 0); |
| 264 | 272 | ret.put("msg", "success"); | ... | ... |
src/main/java/com/genersoft/iot/vmp/service/impl/MediaServiceImpl.java
| ... | ... | @@ -42,6 +42,8 @@ public class MediaServiceImpl implements IMediaService { |
| 42 | 42 | streamInfoResult.setWs_fmp4(String.format("ws://%s:%s/%s/%s.live.mp4", mediaInfo.getWanIp(), mediaInfo.getHttpPort(), app, stream)); |
| 43 | 43 | streamInfoResult.setTs(String.format("http://%s:%s/%s/%s.live.ts", mediaInfo.getWanIp(), mediaInfo.getHttpPort(), app, stream)); |
| 44 | 44 | streamInfoResult.setWs_ts(String.format("ws://%s:%s/%s/%s.live.ts", mediaInfo.getWanIp(), mediaInfo.getHttpPort(), app, stream)); |
| 45 | + streamInfoResult.setRtc(String.format("http://%s:%s/index/api/webrtc?app=%s&stream=%s&type=play", mediaInfo.getWanIp(), mediaInfo.getHttpPort(), app, stream)); | |
| 46 | + | |
| 45 | 47 | return streamInfoResult; |
| 46 | 48 | } |
| 47 | 49 | ... | ... |
web_src/index.html
| ... | ... | @@ -6,7 +6,8 @@ |
| 6 | 6 | <title>国标28181</title> |
| 7 | 7 | </head> |
| 8 | 8 | <body> |
| 9 | - <script type="text/javascript" src="./js/EasyWasmPlayer.js"></script> | |
| 9 | + <!-- <script type="text/javascript" src="./js/EasyWasmPlayer.js"></script> --> | |
| 10 | + <script type="text/javascript" src="/static/js/ZLMRTCClient.js"></script> | |
| 10 | 11 | <script type="text/javascript" src="//api.map.baidu.com/api?v=2.0&ak=rk73w8dv1rkE4UdZsataG68VarhYQzrx&s=1"></script> |
| 11 | 12 | <div id="app"></div> |
| 12 | 13 | <!-- built files will be auto injected --> | ... | ... |
web_src/src/components/dialog/devicePlayer.vue
| ... | ... | @@ -136,7 +136,7 @@ |
| 136 | 136 | </template> |
| 137 | 137 | |
| 138 | 138 | <script> |
| 139 | -import player from '../dialog/player.vue' | |
| 139 | +import player from '../dialog/rtcPlayer.vue' | |
| 140 | 140 | export default { |
| 141 | 141 | name: 'devicePlayer', |
| 142 | 142 | props: {}, |
| ... | ... | @@ -250,7 +250,7 @@ export default { |
| 250 | 250 | |
| 251 | 251 | this.hasaudio = hasAudio; |
| 252 | 252 | this.isLoging = false; |
| 253 | - this.videoUrl = streamInfo.ws_flv; | |
| 253 | + this.videoUrl = streamInfo.rtc; | |
| 254 | 254 | this.streamId = streamInfo.streamId; |
| 255 | 255 | this.app = streamInfo.app; |
| 256 | 256 | this.playFromStreamInfo(false, streamInfo) | ... | ... |
web_src/src/components/dialog/rtcPlayer.vue
0 → 100644
| 1 | +<template> | |
| 2 | + <div id="rtcPlayer"> | |
| 3 | + <video id='webRtcPlayerBox' controls autoplay style="text-align:left;"> | |
| 4 | + Your browser is too old which doesn't support HTML5 video. | |
| 5 | + </video> | |
| 6 | + </div> | |
| 7 | +</template> | |
| 8 | + | |
| 9 | +<script> | |
| 10 | +export default { | |
| 11 | + name: 'rtcPlayer', | |
| 12 | + data() { | |
| 13 | + return { | |
| 14 | + webrtcPlayer: null | |
| 15 | + }; | |
| 16 | + }, | |
| 17 | + props: ['videoUrl', 'error', 'hasaudio'], | |
| 18 | + mounted () { | |
| 19 | + this.$nextTick(() =>{ | |
| 20 | + console.log("初始化时的地址为: " + this.videoUrl) | |
| 21 | + this.play(this.videoUrl) | |
| 22 | + }) | |
| 23 | + }, | |
| 24 | + watch:{ | |
| 25 | + videoUrl(newData, oldData){ | |
| 26 | + this.pause(); | |
| 27 | + this.play(newData); | |
| 28 | + }, | |
| 29 | + immediate:true | |
| 30 | + }, | |
| 31 | + methods: { | |
| 32 | + play: function (url) { | |
| 33 | + this.webrtcPlayer = new ZLMRTCClient.Endpoint({ | |
| 34 | + element: document.getElementById('webRtcPlayerBox'),// video 标签 | |
| 35 | + debug: true,// 是否打印日志 | |
| 36 | + zlmsdpUrl: url,//流地址 | |
| 37 | + simulecast: false, | |
| 38 | + useCamera: false, | |
| 39 | + audioEnable: false, | |
| 40 | + videoEnable: false, | |
| 41 | + recvOnly: true, | |
| 42 | + }) | |
| 43 | + this.webrtcPlayer.on(ZLMRTCClient.Events.WEBRTC_ICE_CANDIDATE_ERROR,(e)=>{// ICE 协商出错 | |
| 44 | + console.error('ICE 协商出错') | |
| 45 | + this.eventcallbacK("ICE ERROR", "ICE 协商出错") | |
| 46 | + }); | |
| 47 | + | |
| 48 | + this.webrtcPlayer.on(ZLMRTCClient.Events.WEBRTC_ON_REMOTE_STREAMS,(e)=>{//获取到了远端流,可以播放 | |
| 49 | + console.error('播放成功',e.streams) | |
| 50 | + this.eventcallbacK("playing", "播放成功") | |
| 51 | + }); | |
| 52 | + | |
| 53 | + this.webrtcPlayer.on(ZLMRTCClient.Events.WEBRTC_OFFER_ANWSER_EXCHANGE_FAILED,(e)=>{// offer anwser 交换失败 | |
| 54 | + console.error('offer anwser 交换失败',e) | |
| 55 | + this.eventcallbacK("OFFER ANSWER ERROR ", "offer anwser 交换失败") | |
| 56 | + if (e.code ==-400 && e.msg=="流不存在"){ | |
| 57 | + console.log("111111") | |
| 58 | + setTimeout(()=>{ | |
| 59 | + this.webrtcPlayer.close(); | |
| 60 | + this.play(url) | |
| 61 | + }, 100) | |
| 62 | + | |
| 63 | + } | |
| 64 | + }); | |
| 65 | + | |
| 66 | + this.webrtcPlayer.on(ZLMRTCClient.Events.WEBRTC_ON_LOCAL_STREAM,(s)=>{// 获取到了本地流 | |
| 67 | + | |
| 68 | + // document.getElementById('selfVideo').srcObject=s; | |
| 69 | + this.eventcallbacK("LOCAL STREAM", "获取到了本地流") | |
| 70 | + }); | |
| 71 | + | |
| 72 | + }, | |
| 73 | + pause: function () { | |
| 74 | + if (this.webrtcPlayer != null) { | |
| 75 | + this.webrtcPlayer.close(); | |
| 76 | + this.webrtcPlayer = null; | |
| 77 | + } | |
| 78 | + | |
| 79 | + }, | |
| 80 | + eventcallbacK: function(type, message) { | |
| 81 | + console.log("player 事件回调") | |
| 82 | + console.log(type) | |
| 83 | + console.log(message) | |
| 84 | + } | |
| 85 | + }, | |
| 86 | +} | |
| 87 | +</script> | |
| 88 | + | |
| 89 | +<style> | |
| 90 | + .LodingTitle { | |
| 91 | + min-width: 70px; | |
| 92 | + } | |
| 93 | + #rtcPlayer{ | |
| 94 | + width: 100%; | |
| 95 | + } | |
| 96 | + #webRtcPlayerBox{ | |
| 97 | + width: 100%; | |
| 98 | + max-height: 56vh; | |
| 99 | + background-color: #000; | |
| 100 | + } | |
| 101 | + /* 隐藏logo */ | |
| 102 | + /* .iconqingxiLOGO { | |
| 103 | + display: none !important; | |
| 104 | + } */ | |
| 105 | + | |
| 106 | +</style> | |
| 0 | 107 | \ No newline at end of file | ... | ... |