Skip to content

Commit fa779a1

Browse files
committed
mjpeg图片流加上aac播报
Change-Id: Ie029edb3eabed1f23ca9ef99b7973b92d6cff93f
1 parent 6e2b1db commit fa779a1

File tree

4 files changed

+71
-4
lines changed

4 files changed

+71
-4
lines changed

sdkdemo/src/main/java/com/tencent/iot/explorer/link/demo/video/Command.kt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,10 @@ class Command {
3939
return "ipc.flv?action=live-mjpg&channel=${channel}&quality=standard"
4040
}
4141

42+
fun getVideoMJPEGAACUrlSuffix(): String {
43+
return "ipc.flv?action=live-audio"
44+
}
45+
4246
fun getNvrIpcStatus(channel: Int, type: Int): String {
4347
var typeStr = "live"
4448
when(type) {

sdkdemo/src/main/java/com/tencent/iot/explorer/link/demo/video/playback/cloudPlayback/VideoCloudPlaybackFragment.kt

Lines changed: 35 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,11 @@ import com.tencent.iot.explorer.link.demo.R
1717
import com.tencent.iot.explorer.link.demo.common.customView.CalendarView
1818
import com.tencent.iot.explorer.link.demo.common.customView.timeline.TimeLineView
1919
import com.tencent.iot.explorer.link.demo.common.customView.timeline.TimeLineViewChangeListener
20+
import com.tencent.iot.explorer.link.demo.common.log.L
2021
import com.tencent.iot.explorer.link.demo.common.util.CommonUtils
2122
import com.tencent.iot.explorer.link.demo.core.entity.BaseResponse
2223
import com.tencent.iot.explorer.link.demo.core.entity.VideoHistory
24+
import com.tencent.iot.explorer.link.demo.video.Command
2325
import com.tencent.iot.explorer.link.demo.video.DevInfo
2426
import com.tencent.iot.explorer.link.demo.video.playback.CalendarDialog
2527
import com.tencent.iot.explorer.link.demo.video.playback.CalendarDialog.OnClickedListener
@@ -67,6 +69,7 @@ class VideoCloudPlaybackFragment: VideoPlaybackBaseFragment(), TextureView.Surfa
6769
private var isShowing = false
6870
private lateinit var surface: Surface
6971
private var player : IjkMediaPlayer = IjkMediaPlayer()
72+
var audioPlayer: IjkMediaPlayer? = null
7073
@Volatile
7174
private var updateSeekBarAble = true // 手动拖拽过程的标记
7275

@@ -192,8 +195,8 @@ class VideoCloudPlaybackFragment: VideoPlaybackBaseFragment(), TextureView.Surfa
192195
iv_start?.setImageResource(R.mipmap.start)
193196
pause_tip_layout?.visibility = View.VISIBLE
194197
seekBarJob?.cancel()
195-
video_seekbar.progress = video_seekbar.max
196-
player.seekTo(1)
198+
// video_seekbar.progress = video_seekbar.max
199+
// player.seekTo(1)
197200
}
198201
}
199202

@@ -311,7 +314,7 @@ class VideoCloudPlaybackFragment: VideoPlaybackBaseFragment(), TextureView.Surfa
311314
override fun success(response: String?, reqCode: Int) {
312315
var json = JSONObject.parseObject(response)
313316
Log.d("响应mjpeg===>url", response)
314-
Log.d(tag, "响应mjpeg===>url=${response} end")
317+
315318
json?.let {
316319
it.getJSONObject("Response")?.let {
317320
var eventResp = JSONObject.parseObject(it.toJSONString(), SignedMJPEGUrlResponse::class.java)
@@ -328,6 +331,7 @@ class VideoCloudPlaybackFragment: VideoPlaybackBaseFragment(), TextureView.Surfa
328331
}
329332

330333
private fun startMJPEGVideo(vUrl: String, aUrl: String) {
334+
Log.d(tag, "响应mjpeg===>vUrl=${vUrl} \nand aURL===>${aUrl}")
331335
player.reset()
332336
player.setSurface(this.surface)
333337
player.dataSource = vUrl
@@ -352,6 +356,34 @@ class VideoCloudPlaybackFragment: VideoPlaybackBaseFragment(), TextureView.Surfa
352356
}
353357
}
354358
}
359+
360+
audioPlayer?.release()
361+
audioPlayer = IjkMediaPlayer()
362+
audioPlayer?.let {
363+
val url = aUrl
364+
it.reset()
365+
366+
// it.setOption(IjkMediaPlayer.OPT_CATEGORY_FORMAT, "analyzemaxduration", 100)
367+
it.setOption(IjkMediaPlayer.OPT_CATEGORY_FORMAT, "probesize", 512)
368+
it.setOption(IjkMediaPlayer.OPT_CATEGORY_PLAYER, "packet-buffering", 0)
369+
it.setOption(IjkMediaPlayer.OPT_CATEGORY_PLAYER, "start-on-prepared", 1)
370+
it.setOption(IjkMediaPlayer.OPT_CATEGORY_CODEC, "threads", 1)
371+
it.setOption(IjkMediaPlayer.OPT_CATEGORY_PLAYER, "sync-av-start", 0)
372+
it.setOption(IjkMediaPlayer.OPT_CATEGORY_PLAYER, "mediacodec",1)
373+
it.setOption(IjkMediaPlayer.OPT_CATEGORY_PLAYER, "mediacodec-auto-rotate", 1)
374+
it.setOption(IjkMediaPlayer.OPT_CATEGORY_PLAYER, "mediacodec-handle-resolution-change", 1)
375+
//
376+
// it.setFrameSpeed(1.5f)
377+
// while (!::surface.isInitialized) {
378+
// delay(50)
379+
// L.e("delay for waiting surface.")
380+
// }
381+
it.setSurface(surface)
382+
it.dataSource = url
383+
384+
it.prepareAsync()
385+
it.start()
386+
}
355387
}
356388

357389
private fun startVideo(url: String, offset: Long) {

sdkdemo/src/main/java/com/tencent/iot/explorer/link/demo/video/playback/localPlayback/VideoLocalPlaybackFragment.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -827,7 +827,7 @@ class VideoLocalPlaybackFragment : VideoPlaybackBaseFragment(), TextureView.Surf
827827

828828
App.data.accessInfo?.let { access ->
829829
devInfo?.let {
830-
XP2P.stopService("${access.productId}/${it.DeviceName}")
830+
// XP2P.stopService("${access.productId}/${it.DeviceName}")
831831
}
832832
}
833833
XP2P.setCallback(null)

sdkdemo/src/main/java/com/tencent/iot/explorer/link/demo/video/preview/VideoPreviewMJPEGActivity.kt

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,7 @@ class VideoPreviewMJPEGActivity : VideoBaseActivity(), EventView, TextureView.Su
7171
private var records : MutableList<ActionRecord> = ArrayList()
7272
lateinit var presenter: EventPresenter
7373
lateinit var player : IjkMediaPlayer
74+
var audioPlayer : IjkMediaPlayer? = null
7475
lateinit var surface: Surface
7576
@Volatile
7677
var audioAble = true
@@ -432,6 +433,7 @@ class VideoPreviewMJPEGActivity : VideoBaseActivity(), EventView, TextureView.Su
432433
showTip = false
433434
startShowVideoTime = System.currentTimeMillis()
434435
player.release()
436+
audioPlayer?.release()
435437
launch (Dispatchers.Main) {
436438
layout_video_preview?.removeView(v_preview)
437439
layout_video_preview?.addView(v_preview, 0)
@@ -462,6 +464,34 @@ class VideoPreviewMJPEGActivity : VideoBaseActivity(), EventView, TextureView.Su
462464
it.prepareAsync()
463465
it.start()
464466
}
467+
468+
469+
audioPlayer = IjkMediaPlayer()
470+
audioPlayer?.let {
471+
val url = urlPrefix + Command.getVideoMJPEGAACUrlSuffix()
472+
it.reset()
473+
474+
it.setOption(IjkMediaPlayer.OPT_CATEGORY_FORMAT, "analyzemaxduration", 100)
475+
it.setOption(IjkMediaPlayer.OPT_CATEGORY_FORMAT, "probesize", 256)
476+
it.setOption(IjkMediaPlayer.OPT_CATEGORY_PLAYER, "packet-buffering", 0)
477+
it.setOption(IjkMediaPlayer.OPT_CATEGORY_PLAYER, "start-on-prepared", 1)
478+
it.setOption(IjkMediaPlayer.OPT_CATEGORY_CODEC, "threads", 1)
479+
it.setOption(IjkMediaPlayer.OPT_CATEGORY_PLAYER, "sync-av-start", 0)
480+
it.setOption(IjkMediaPlayer.OPT_CATEGORY_PLAYER, "mediacodec",1)
481+
it.setOption(IjkMediaPlayer.OPT_CATEGORY_PLAYER, "mediacodec-auto-rotate", 1)
482+
it.setOption(IjkMediaPlayer.OPT_CATEGORY_PLAYER, "mediacodec-handle-resolution-change", 1)
483+
484+
it.setFrameSpeed(1.5f)
485+
while (!::surface.isInitialized) {
486+
delay(50)
487+
L.e("delay for waiting surface.")
488+
}
489+
it.setSurface(surface)
490+
it.dataSource = url
491+
492+
it.prepareAsync()
493+
it.start()
494+
}
465495
}
466496
}
467497

@@ -585,6 +615,7 @@ class VideoPreviewMJPEGActivity : VideoBaseActivity(), EventView, TextureView.Su
585615
CommonUtils.refreshVideoList(this@VideoPreviewMJPEGActivity, filePath)
586616
}
587617

618+
audioPlayer?.release()
588619
countDownLatchs.clear()
589620
// 关闭守护线程
590621
keepAliveThreadRuning = false

0 commit comments

Comments
 (0)