视频播放2
This commit is contained in:
@@ -80,7 +80,8 @@
|
|||||||
android:exported="false" />
|
android:exported="false" />
|
||||||
<activity
|
<activity
|
||||||
android:name=".liveVideo.AlarmLogActivity"
|
android:name=".liveVideo.AlarmLogActivity"
|
||||||
android:exported="false" />
|
android:exported="false"
|
||||||
|
android:configChanges="orientation|screenSize|keyboardHidden" />
|
||||||
<activity
|
<activity
|
||||||
android:name=".liveVideo.SettingsActivity"
|
android:name=".liveVideo.SettingsActivity"
|
||||||
android:exported="false" />
|
android:exported="false" />
|
||||||
|
|||||||
@@ -28,7 +28,7 @@ import com.example.defenseapplication.adapter.WifiListAdapter
|
|||||||
import com.example.defenseapplication.databinding.AddFamilyActivityBinding
|
import com.example.defenseapplication.databinding.AddFamilyActivityBinding
|
||||||
import com.example.defenseapplication.databinding.DialogWifiListBinding
|
import com.example.defenseapplication.databinding.DialogWifiListBinding
|
||||||
import com.gyf.immersionbar.ImmersionBar
|
import com.gyf.immersionbar.ImmersionBar
|
||||||
|
//选择Wi-Fi
|
||||||
class AddFamilyActivity : AppCompatActivity() {
|
class AddFamilyActivity : AppCompatActivity() {
|
||||||
|
|
||||||
private lateinit var binding: AddFamilyActivityBinding
|
private lateinit var binding: AddFamilyActivityBinding
|
||||||
|
|||||||
@@ -1,16 +1,25 @@
|
|||||||
package com.example.defenseapplication.liveVideo
|
package com.example.defenseapplication.liveVideo
|
||||||
|
|
||||||
|
import android.content.res.Configuration
|
||||||
import android.graphics.Color
|
import android.graphics.Color
|
||||||
import android.os.Bundle
|
import android.os.Bundle
|
||||||
|
import android.util.Log
|
||||||
|
import android.view.View
|
||||||
|
import android.widget.LinearLayout
|
||||||
|
import android.widget.Toast
|
||||||
|
import androidx.activity.OnBackPressedCallback
|
||||||
import androidx.appcompat.app.AppCompatActivity
|
import androidx.appcompat.app.AppCompatActivity
|
||||||
import androidx.recyclerview.widget.LinearLayoutManager
|
import androidx.recyclerview.widget.LinearLayoutManager
|
||||||
|
import chuangyuan.ycj.videolibrary.listener.VideoInfoListener
|
||||||
|
import chuangyuan.ycj.videolibrary.video.ExoUserPlayer
|
||||||
|
import chuangyuan.ycj.videolibrary.video.VideoPlayerManager
|
||||||
|
import com.example.defenseapplication.R
|
||||||
import com.example.defenseapplication.adapter.AlarmLogAdapter
|
import com.example.defenseapplication.adapter.AlarmLogAdapter
|
||||||
import com.example.defenseapplication.databinding.AlarmLogActivityBinding
|
import com.example.defenseapplication.databinding.AlarmLogActivityBinding
|
||||||
import com.gyf.immersionbar.ImmersionBar
|
import com.gyf.immersionbar.ImmersionBar
|
||||||
import java.util.*
|
import java.util.*
|
||||||
import com.bigkoo.pickerview.builder.TimePickerBuilder
|
import com.bigkoo.pickerview.builder.TimePickerBuilder
|
||||||
import com.bigkoo.pickerview.listener.OnTimeSelectListener
|
import com.bigkoo.pickerview.listener.OnTimeSelectListener
|
||||||
import com.example.defenseapplication.R
|
|
||||||
|
|
||||||
//告警记录
|
//告警记录
|
||||||
class AlarmLogActivity : AppCompatActivity() {
|
class AlarmLogActivity : AppCompatActivity() {
|
||||||
@@ -18,6 +27,7 @@ class AlarmLogActivity : AppCompatActivity() {
|
|||||||
private lateinit var calendar: Calendar
|
private lateinit var calendar: Calendar
|
||||||
private var adapter: AlarmLogAdapter? = null
|
private var adapter: AlarmLogAdapter? = null
|
||||||
private val alarmList = mutableListOf<String>()
|
private val alarmList = mutableListOf<String>()
|
||||||
|
private lateinit var exoPlayerManager: ExoUserPlayer
|
||||||
|
|
||||||
override fun onCreate(savedInstanceState: Bundle?) {
|
override fun onCreate(savedInstanceState: Bundle?) {
|
||||||
super.onCreate(savedInstanceState)
|
super.onCreate(savedInstanceState)
|
||||||
@@ -25,14 +35,65 @@ class AlarmLogActivity : AppCompatActivity() {
|
|||||||
setContentView(binding.root)
|
setContentView(binding.root)
|
||||||
ImmersionBar.with(this)
|
ImmersionBar.with(this)
|
||||||
.statusBarDarkFont(true)
|
.statusBarDarkFont(true)
|
||||||
.titleBar(binding.topBar)
|
.titleBar(binding.exoPlayContextId)
|
||||||
.init()
|
.init()
|
||||||
|
|
||||||
calendar = Calendar.getInstance()
|
calendar = Calendar.getInstance()
|
||||||
updateDateDisplay()
|
updateDateDisplay()
|
||||||
|
initVideoPlayer()
|
||||||
initRecyclerView()
|
initRecyclerView()
|
||||||
loadAlarmList()
|
loadAlarmList()
|
||||||
initListener()
|
initListener()
|
||||||
|
|
||||||
|
onBackPressedDispatcher.addCallback(this, object : OnBackPressedCallback(true) {
|
||||||
|
override fun handleOnBackPressed() {
|
||||||
|
if (exoPlayerManager.onBackPressed()) {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
finish()
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun dpToPx(dp: Int): Int {
|
||||||
|
val density = resources.displayMetrics.density
|
||||||
|
return (dp * density).toInt()
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun initVideoPlayer() {
|
||||||
|
val videoPlayerView = binding.exoPlayContextId
|
||||||
|
|
||||||
|
exoPlayerManager = VideoPlayerManager.Builder(VideoPlayerManager.TYPE_PLAY_GESTURE, videoPlayerView)
|
||||||
|
.setPlayUri("https://media.w3.org/2010/05/sintel/trailer.mp4")
|
||||||
|
.setPosition(0)
|
||||||
|
.addVideoInfoListener(object : VideoInfoListener {
|
||||||
|
override fun onPlayStart(p0: Long) {
|
||||||
|
Log.d("AlarmLogActivity", "视频开始播放")
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun onLoadingChanged() {
|
||||||
|
// 视频加载状态变化
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun onPlayerError(p0: com.google.android.exoplayer2.ExoPlaybackException?) {
|
||||||
|
Toast.makeText(this@AlarmLogActivity, "播放失败", Toast.LENGTH_SHORT).show()
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun onPlayEnd() {
|
||||||
|
Log.d("AlarmLogActivity", "播放结束")
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun isPlaying(p0: Boolean) {
|
||||||
|
// p0 表示当前是否正在播放
|
||||||
|
}
|
||||||
|
|
||||||
|
fun onRepeatModeChanged(p0: Int) {
|
||||||
|
// 循环模式改变时的回调
|
||||||
|
}
|
||||||
|
})
|
||||||
|
.create()
|
||||||
|
|
||||||
|
exoPlayerManager.startPlayer()
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun initRecyclerView() {
|
private fun initRecyclerView() {
|
||||||
@@ -58,14 +119,52 @@ class AlarmLogActivity : AppCompatActivity() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private fun initListener() {
|
private fun initListener() {
|
||||||
binding.btnBack.setOnClickListener {
|
|
||||||
finish()
|
|
||||||
}
|
|
||||||
binding.expandImg.setOnClickListener {
|
binding.expandImg.setOnClickListener {
|
||||||
showDatePicker()
|
showDatePicker()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
override fun onResume() {
|
||||||
|
super.onResume()
|
||||||
|
exoPlayerManager.onResume()
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun onPause() {
|
||||||
|
super.onPause()
|
||||||
|
exoPlayerManager.onPause()
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun onDestroy() {
|
||||||
|
super.onDestroy()
|
||||||
|
exoPlayerManager.onDestroy()
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun onConfigurationChanged(newConfig: Configuration) {
|
||||||
|
super.onConfigurationChanged(newConfig)
|
||||||
|
|
||||||
|
if (newConfig.orientation == Configuration.ORIENTATION_LANDSCAPE) {
|
||||||
|
// 进入横屏(全屏)模式
|
||||||
|
binding.titleLayout.visibility = View.GONE
|
||||||
|
binding.alarmListRecyclerView.visibility = View.GONE
|
||||||
|
|
||||||
|
val params = binding.exoPlayContextId.layoutParams
|
||||||
|
params.width = LinearLayout.LayoutParams.MATCH_PARENT
|
||||||
|
params.height = LinearLayout.LayoutParams.MATCH_PARENT
|
||||||
|
binding.exoPlayContextId.layoutParams = params
|
||||||
|
} else if (newConfig.orientation == Configuration.ORIENTATION_PORTRAIT) {
|
||||||
|
// 进入竖屏(非全屏)模式
|
||||||
|
binding.titleLayout.visibility = View.VISIBLE
|
||||||
|
binding.alarmListRecyclerView.visibility = View.VISIBLE
|
||||||
|
|
||||||
|
val params = binding.exoPlayContextId.layoutParams
|
||||||
|
params.width = LinearLayout.LayoutParams.MATCH_PARENT
|
||||||
|
params.height = dpToPx(250)
|
||||||
|
binding.exoPlayContextId.layoutParams = params
|
||||||
|
}
|
||||||
|
|
||||||
|
exoPlayerManager.onConfigurationChanged(newConfig)
|
||||||
|
}
|
||||||
|
|
||||||
private fun showDatePicker() {
|
private fun showDatePicker() {
|
||||||
val timePicker = TimePickerBuilder(this, OnTimeSelectListener { date, _ ->
|
val timePicker = TimePickerBuilder(this, OnTimeSelectListener { date, _ ->
|
||||||
calendar.time = date
|
calendar.time = date
|
||||||
|
|||||||
@@ -27,7 +27,6 @@ import android.view.ViewGroup
|
|||||||
import android.widget.ImageView
|
import android.widget.ImageView
|
||||||
import android.widget.LinearLayout
|
import android.widget.LinearLayout
|
||||||
|
|
||||||
private const val TAG = "LiveVideoActivity"
|
|
||||||
//智能防御机A1
|
//智能防御机A1
|
||||||
class LiveVideoActivity : BaseActivity() {
|
class LiveVideoActivity : BaseActivity() {
|
||||||
private lateinit var binding: LiveVideoActivityBinding
|
private lateinit var binding: LiveVideoActivityBinding
|
||||||
@@ -90,7 +89,7 @@ class LiveVideoActivity : BaseActivity() {
|
|||||||
.addVideoInfoListener(object : VideoInfoListener {
|
.addVideoInfoListener(object : VideoInfoListener {
|
||||||
// 注意:此处的 p0: Long 是视频开始播放时的位置信息,可以按需使用
|
// 注意:此处的 p0: Long 是视频开始播放时的位置信息,可以按需使用
|
||||||
override fun onPlayStart(p0: Long) {
|
override fun onPlayStart(p0: Long) {
|
||||||
Log.d(TAG, "视频开始播放")
|
Log.d("AlarmLogActivity", "视频开始播放")
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun onLoadingChanged() {
|
override fun onLoadingChanged() {
|
||||||
@@ -102,7 +101,7 @@ class LiveVideoActivity : BaseActivity() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
override fun onPlayEnd() {
|
override fun onPlayEnd() {
|
||||||
Log.d(TAG, "播放结束")
|
Log.d("AlarmLogActivity", "播放结束")
|
||||||
}
|
}
|
||||||
|
|
||||||
// 修正点:库的接口要求必须实现 isPlaying 方法
|
// 修正点:库的接口要求必须实现 isPlaying 方法
|
||||||
|
|||||||
Binary file not shown.
|
Before Width: | Height: | Size: 2.5 KiB After Width: | Height: | Size: 639 B |
Binary file not shown.
|
Before Width: | Height: | Size: 3.6 KiB After Width: | Height: | Size: 1.3 KiB |
@@ -1,156 +1,23 @@
|
|||||||
<?xml version="1.0" encoding="utf-8"?>
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
|
xmlns:app="http://schemas.android.com/apk/res-auto"
|
||||||
android:id="@+id/main"
|
android:id="@+id/main"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="match_parent"
|
android:layout_height="match_parent"
|
||||||
android:background="#F9F9F9"
|
android:background="#F9F9F9"
|
||||||
android:orientation="vertical">
|
android:orientation="vertical">
|
||||||
|
|
||||||
<LinearLayout
|
<!-- 视频播放区域 -->
|
||||||
android:id="@+id/topBar"
|
<chuangyuan.ycj.videolibrary.widget.VideoPlayerView
|
||||||
|
android:id="@+id/exoPlayContextId"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="56dp"
|
android:layout_height="250dp"
|
||||||
android:background="#FFFFFF"
|
android:background="@android:color/transparent"
|
||||||
android:gravity="center_vertical"
|
app:use_controller="true"/>
|
||||||
android:orientation="horizontal"
|
|
||||||
android:paddingLeft="16dp"
|
|
||||||
android:paddingRight="16dp">
|
|
||||||
|
|
||||||
<ImageView
|
|
||||||
android:id="@+id/btnBack"
|
|
||||||
android:layout_width="24dp"
|
|
||||||
android:layout_height="24dp"
|
|
||||||
android:src="@drawable/back" />
|
|
||||||
|
|
||||||
<TextView
|
|
||||||
android:layout_width="0dp"
|
|
||||||
android:layout_height="wrap_content"
|
|
||||||
android:layout_weight="1"
|
|
||||||
android:gravity="center"
|
|
||||||
android:text="@string/alarm_log_title"
|
|
||||||
android:textSize="16sp"
|
|
||||||
android:textStyle="bold" />
|
|
||||||
|
|
||||||
<View
|
|
||||||
android:layout_width="24dp"
|
|
||||||
android:layout_height="24dp" />
|
|
||||||
|
|
||||||
</LinearLayout>
|
|
||||||
|
|
||||||
<FrameLayout
|
|
||||||
android:layout_width="match_parent"
|
|
||||||
android:layout_height="280dp"
|
|
||||||
android:background="#000000">
|
|
||||||
|
|
||||||
<ImageView
|
|
||||||
android:layout_width="match_parent"
|
|
||||||
android:layout_height="match_parent"
|
|
||||||
android:scaleType="centerCrop"
|
|
||||||
android:src="@drawable/img" />
|
|
||||||
|
|
||||||
<LinearLayout
|
|
||||||
android:layout_width="match_parent"
|
|
||||||
android:layout_height="match_parent"
|
|
||||||
android:orientation="vertical">
|
|
||||||
|
|
||||||
<LinearLayout
|
|
||||||
android:layout_width="match_parent"
|
|
||||||
android:layout_height="0dp"
|
|
||||||
android:layout_weight="1"
|
|
||||||
android:gravity="top|end"
|
|
||||||
android:padding="16dp">
|
|
||||||
|
|
||||||
<LinearLayout
|
|
||||||
android:layout_width="wrap_content"
|
|
||||||
android:layout_height="wrap_content"
|
|
||||||
android:orientation="vertical">
|
|
||||||
|
|
||||||
<ImageView
|
|
||||||
android:layout_width="40dp"
|
|
||||||
android:layout_height="40dp"
|
|
||||||
android:layout_marginBottom="8dp"
|
|
||||||
android:src="@drawable/download" />
|
|
||||||
|
|
||||||
<ImageView
|
|
||||||
android:layout_width="40dp"
|
|
||||||
android:layout_height="40dp"
|
|
||||||
android:layout_marginBottom="8dp"
|
|
||||||
android:src="@drawable/mute"/>
|
|
||||||
|
|
||||||
<ImageView
|
|
||||||
android:layout_width="40dp"
|
|
||||||
android:layout_height="40dp"
|
|
||||||
android:layout_marginBottom="8dp"
|
|
||||||
android:src="@drawable/delete" />
|
|
||||||
|
|
||||||
<ImageView
|
|
||||||
android:layout_width="40dp"
|
|
||||||
android:layout_height="40dp"
|
|
||||||
android:src="@drawable/mute"/>
|
|
||||||
|
|
||||||
</LinearLayout>
|
|
||||||
|
|
||||||
</LinearLayout>
|
|
||||||
|
|
||||||
<LinearLayout
|
|
||||||
android:layout_width="match_parent"
|
|
||||||
android:layout_height="0dp"
|
|
||||||
android:layout_weight="1"
|
|
||||||
android:gravity="bottom|end"
|
|
||||||
android:padding="16dp">
|
|
||||||
|
|
||||||
<ImageView
|
|
||||||
android:layout_width="40dp"
|
|
||||||
android:layout_height="40dp"
|
|
||||||
android:src="@drawable/full_screen" />
|
|
||||||
|
|
||||||
</LinearLayout>
|
|
||||||
|
|
||||||
</LinearLayout>
|
|
||||||
|
|
||||||
<LinearLayout
|
|
||||||
android:layout_width="match_parent"
|
|
||||||
android:layout_height="wrap_content"
|
|
||||||
android:layout_gravity="bottom"
|
|
||||||
android:background="#000000"
|
|
||||||
android:orientation="horizontal"
|
|
||||||
android:padding="8dp">
|
|
||||||
|
|
||||||
<ImageView
|
|
||||||
android:id="@+id/ivPlay"
|
|
||||||
android:layout_width="32dp"
|
|
||||||
android:layout_height="32dp"
|
|
||||||
android:src="@drawable/start" />
|
|
||||||
|
|
||||||
<TextView
|
|
||||||
android:layout_width="wrap_content"
|
|
||||||
android:layout_height="wrap_content"
|
|
||||||
android:layout_marginLeft="8dp"
|
|
||||||
android:text="01:05"
|
|
||||||
android:textColor="#FFFFFF"
|
|
||||||
android:textSize="14sp" />
|
|
||||||
|
|
||||||
<SeekBar
|
|
||||||
android:id="@+id/seekBar"
|
|
||||||
android:layout_width="0dp"
|
|
||||||
android:layout_height="wrap_content"
|
|
||||||
android:layout_weight="1"
|
|
||||||
android:layout_marginLeft="8dp"
|
|
||||||
android:layout_marginRight="8dp"
|
|
||||||
android:progress="20" />
|
|
||||||
|
|
||||||
<TextView
|
|
||||||
android:layout_width="wrap_content"
|
|
||||||
android:layout_height="wrap_content"
|
|
||||||
android:text="05:05"
|
|
||||||
android:textColor="#FFFFFF"
|
|
||||||
android:textSize="14sp" />
|
|
||||||
|
|
||||||
</LinearLayout>
|
|
||||||
|
|
||||||
</FrameLayout>
|
|
||||||
|
|
||||||
<LinearLayout
|
<LinearLayout
|
||||||
|
android:id="@+id/titleLayout"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="48dp"
|
android:layout_height="48dp"
|
||||||
android:background="#FFFFFF"
|
android:background="#FFFFFF"
|
||||||
@@ -188,4 +55,5 @@
|
|||||||
android:layout_weight="1"
|
android:layout_weight="1"
|
||||||
android:background="#FFFFFF" />
|
android:background="#FFFFFF" />
|
||||||
|
|
||||||
|
|
||||||
</LinearLayout>
|
</LinearLayout>
|
||||||
@@ -169,6 +169,7 @@
|
|||||||
android:padding="16dp">
|
android:padding="16dp">
|
||||||
|
|
||||||
<LinearLayout
|
<LinearLayout
|
||||||
|
android:id="@+id/xq"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:orientation="horizontal"
|
android:orientation="horizontal"
|
||||||
@@ -186,7 +187,6 @@
|
|||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:layout_weight="1" />
|
android:layout_weight="1" />
|
||||||
<ImageView
|
<ImageView
|
||||||
android:id="@+id/xq"
|
|
||||||
android:layout_width="24dp"
|
android:layout_width="24dp"
|
||||||
android:layout_height="24dp"
|
android:layout_height="24dp"
|
||||||
android:src="@drawable/right_back"/>
|
android:src="@drawable/right_back"/>
|
||||||
|
|||||||
Reference in New Issue
Block a user