Skip to content

Commit b11c614

Browse files
sevenhhesevenhhe
authored andcommitted
ijkplayer 自动切换软硬件解码
Change-Id: If0a68fa45af5ff8d375bbdef08dd2f1e041566ca
1 parent 6dd54ca commit b11c614

File tree

3 files changed

+24
-1
lines changed

3 files changed

+24
-1
lines changed

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

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,6 @@ import com.tencent.iot.explorer.link.demo.video.utils.ToastDialog
3232
import com.tencent.xnet.XP2P
3333
import com.tencent.xnet.XP2PCallback
3434
import kotlinx.android.synthetic.main.activity_video_preview.*
35-
import kotlinx.android.synthetic.main.fragment_video_cloud_playback.*
3635
import kotlinx.android.synthetic.main.fragment_video_local_playback.*
3736
import kotlinx.android.synthetic.main.fragment_video_local_playback.iv_left_go
3837
import kotlinx.android.synthetic.main.fragment_video_local_playback.iv_right_go
@@ -454,7 +453,13 @@ class VideoLocalPlaybackFragment: VideoPlaybackBaseFragment(), TextureView.Surfa
454453
}
455454

456455
private fun setPlayerUrl(suffix: String, offset: Long) {
456+
player.release()
457+
launch (Dispatchers.Main) {
458+
layout_video?.removeView(local_palayback_video)
459+
layout_video?.addView(local_palayback_video, 0)
460+
}
457461

462+
player = IjkMediaPlayer()
458463
player?.let {
459464
var url = urlPrefix + suffix
460465
Log.d(TAG, "setPlayerUrl url $url")
@@ -470,6 +475,10 @@ class VideoLocalPlaybackFragment: VideoPlaybackBaseFragment(), TextureView.Surfa
470475
}
471476
it.setOption(IjkMediaPlayer.OPT_CATEGORY_CODEC, "threads", 1)
472477
it.setOption(IjkMediaPlayer.OPT_CATEGORY_PLAYER, "sync-av-start", 0)
478+
it.setOption(IjkMediaPlayer.OPT_CATEGORY_PLAYER, "mediacodec",1)
479+
it.setOption(IjkMediaPlayer.OPT_CATEGORY_PLAYER, "mediacodec-auto-rotate", 1)
480+
it.setOption(IjkMediaPlayer.OPT_CATEGORY_PLAYER, "mediacodec-handle-resolution-change", 1)
481+
473482

474483
it.setSurface(this.surface)
475484
it.dataSource = url

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,10 @@ class VideoMultiPreviewActivity : VideoBaseActivity(), XP2PCallback, CoroutineSc
139139
player.setOption(IjkMediaPlayer.OPT_CATEGORY_CODEC, "threads", 1)
140140
player.setOption(IjkMediaPlayer.OPT_CATEGORY_PLAYER, "sync-av-start", 0)
141141
player.setOption(IjkMediaPlayer.OPT_CATEGORY_FORMAT, "reconnect", 1)
142+
player.setOption(IjkMediaPlayer.OPT_CATEGORY_PLAYER, "mediacodec",1)
143+
player.setOption(IjkMediaPlayer.OPT_CATEGORY_PLAYER, "mediacodec-auto-rotate", 1)
144+
player.setOption(IjkMediaPlayer.OPT_CATEGORY_PLAYER, "mediacodec-handle-resolution-change", 1)
145+
142146
player.dataSource = url
143147
player.prepareAsync()
144148
player.start()

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

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -414,6 +414,13 @@ class VideoPreviewActivity : VideoBaseActivity(), EventView, TextureView.Surface
414414
private fun setPlayerUrl(suffix: String) {
415415
showTip = false
416416
startShowVideoTime = System.currentTimeMillis()
417+
player.release()
418+
launch (Dispatchers.Main) {
419+
layout_video_preview?.removeView(v_preview)
420+
layout_video_preview?.addView(v_preview, 0)
421+
}
422+
423+
player = IjkMediaPlayer()
417424
player?.let {
418425
val url = urlPrefix + suffix
419426
it.reset()
@@ -424,6 +431,9 @@ class VideoPreviewActivity : VideoBaseActivity(), EventView, TextureView.Surface
424431
it.setOption(IjkMediaPlayer.OPT_CATEGORY_PLAYER, "start-on-prepared", 1)
425432
it.setOption(IjkMediaPlayer.OPT_CATEGORY_CODEC, "threads", 1)
426433
it.setOption(IjkMediaPlayer.OPT_CATEGORY_PLAYER, "sync-av-start", 0)
434+
it.setOption(IjkMediaPlayer.OPT_CATEGORY_PLAYER, "mediacodec",1)
435+
it.setOption(IjkMediaPlayer.OPT_CATEGORY_PLAYER, "mediacodec-auto-rotate", 1)
436+
it.setOption(IjkMediaPlayer.OPT_CATEGORY_PLAYER, "mediacodec-handle-resolution-change", 1)
427437

428438
it.setSurface(this.surface)
429439
it.dataSource = url

0 commit comments

Comments
 (0)