Skip to content

Commit

Permalink
fix gson crash
Browse files Browse the repository at this point in the history
  • Loading branch information
lizongying committed May 27, 2024
1 parent 31ec13e commit bcfca9e
Show file tree
Hide file tree
Showing 6 changed files with 26 additions and 70 deletions.
2 changes: 1 addition & 1 deletion HISTORY.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
## 更新日志

### v2.0.8
### v2.0.9

* 修复部分设备闪退的问题
* 修复设置页可能显示不全的问题
Expand Down
17 changes: 12 additions & 5 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,11 @@ dependencies {
implementation "androidx.media3:media3-ui:$media3_version"

// For media playback using ExoPlayer
implementation "androidx.media3:media3-exoplayer:$media3_version"
implementation ("com.google.guava:guava:31.1-android")
implementation ("androidx.media3:media3-common:$media3_version") {
exclude group: 'com.google.common', module: 'guava'
}
implementation ("androidx.media3:media3-exoplayer:$media3_version")

// For HLS playback support with ExoPlayer
implementation "androidx.media3:media3-exoplayer-hls:$media3_version"
Expand Down Expand Up @@ -133,9 +137,12 @@ dependencies {
implementation "org.jetbrains.kotlinx:kotlinx-serialization-json:1.6.2"
implementation("org.jetbrains.kotlinx:kotlinx-coroutines-android:1.8.0-RC")

implementation 'com.google.android.exoplayer:exoplayer-ui:2.13.3'
implementation 'com.google.android.exoplayer:exoplayer-core:2.13.3'
implementation 'com.google.android.exoplayer:exoplayer-hls:2.13.3'

implementation 'javax.annotation:javax.annotation-api:1.3.2'
}

configurations.configureEach {
resolutionStrategy {
force 'com.google.code.gson:gson:2.10.1'
force 'com.google.guava:guava:31.1-android'
}
}
46 changes: 2 additions & 44 deletions app/src/main/java/com/lizongying/mytv/PlayerFragment.kt
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@ package com.lizongying.mytv
import android.os.Bundle
import android.util.Log
import android.view.LayoutInflater
import android.view.SurfaceHolder
import android.view.SurfaceView
import android.view.View
import android.view.ViewGroup
import android.view.ViewTreeObserver
Expand All @@ -15,41 +13,26 @@ import androidx.media3.common.PlaybackException
import androidx.media3.common.Player
import androidx.media3.common.VideoSize
import androidx.media3.common.util.UnstableApi
import androidx.media3.exoplayer.DefaultRenderersFactory
import androidx.media3.exoplayer.ExoPlayer
import androidx.media3.ui.PlayerView
import com.google.android.exoplayer2.SimpleExoPlayer
import com.lizongying.mytv.databinding.PlayerBinding
import com.lizongying.mytv.models.TVViewModel


class PlayerFragment : Fragment(), SurfaceHolder.Callback {
class PlayerFragment : Fragment() {

private var _binding: PlayerBinding? = null
private var playerView: PlayerView? = null
private var tvViewModel: TVViewModel? = null
private val aspectRatio = 16f / 9f


private lateinit var surfaceView: SurfaceView
private lateinit var surfaceHolder: SurfaceHolder
private var exoPlayer: SimpleExoPlayer? = null

override fun onCreateView(
inflater: LayoutInflater, container: ViewGroup?,
savedInstanceState: Bundle?
): View {
_binding = PlayerBinding.inflate(inflater, container, false)

if (Utils.isTmallDevice()) {
_binding!!.playerView.visibility = View.GONE
surfaceView = _binding!!.surfaceView
surfaceHolder = surfaceView.holder
surfaceHolder.addCallback(this)
} else {
_binding!!.surfaceView.visibility = View.GONE
playerView = _binding!!.playerView
}
playerView = _binding!!.playerView

playerView?.viewTreeObserver?.addOnGlobalLayoutListener(object :
ViewTreeObserver.OnGlobalLayoutListener {
Expand Down Expand Up @@ -111,10 +94,6 @@ class PlayerFragment : Fragment(), SurfaceHolder.Callback {
setMediaItem(MediaItem.fromUri(tvViewModel.getVideoUrlCurrent()))
prepare()
}
exoPlayer?.run {
setMediaItem(com.google.android.exoplayer2.MediaItem.fromUri(tvViewModel.getVideoUrlCurrent()))
prepare()
}
}

override fun onStart() {
Expand All @@ -125,11 +104,6 @@ class PlayerFragment : Fragment(), SurfaceHolder.Callback {
playerView!!.player?.prepare()
playerView!!.player?.play()
}
if (exoPlayer?.isPlaying == false) {
Log.i(TAG, "replay")
exoPlayer?.prepare()
exoPlayer?.play()
}
}

override fun onResume() {
Expand All @@ -142,17 +116,13 @@ class PlayerFragment : Fragment(), SurfaceHolder.Callback {
if (playerView != null && playerView!!.player?.isPlaying == true) {
playerView!!.player?.stop()
}
if (exoPlayer?.isPlaying == true) {
exoPlayer?.stop()
}
}

override fun onDestroy() {
super.onDestroy()
if (playerView != null) {
playerView!!.player?.release()
}
exoPlayer?.release()
}

override fun onDestroyView() {
Expand All @@ -163,16 +133,4 @@ class PlayerFragment : Fragment(), SurfaceHolder.Callback {
companion object {
private const val TAG = "PlayerFragment"
}

override fun surfaceCreated(holder: SurfaceHolder) {
exoPlayer = SimpleExoPlayer.Builder(requireContext()).build()
exoPlayer?.setVideoSurfaceHolder(surfaceHolder)
exoPlayer?.playWhenReady = true
}

override fun surfaceChanged(holder: SurfaceHolder, format: Int, width: Int, height: Int) {
}

override fun surfaceDestroyed(holder: SurfaceHolder) {
}
}
20 changes: 10 additions & 10 deletions app/src/main/java/com/lizongying/mytv/api/ApiClient.kt
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package com.lizongying.mytv.api

import android.os.Build
import android.util.Log
import com.google.gson.Gson
import com.lizongying.mytv.jce.JceConverterFactory
import com.lizongying.mytv.requests.ReleaseService
import okhttp3.ConnectionSpec
Expand All @@ -11,8 +12,6 @@ import okhttp3.TlsVersion
import retrofit2.Retrofit
import retrofit2.converter.gson.GsonConverterFactory
import retrofit2.converter.protobuf.ProtoConverterFactory
import java.net.InetSocketAddress
import java.net.Proxy
import javax.net.ssl.SSLContext
import javax.net.ssl.TrustManager
import javax.net.ssl.X509TrustManager
Expand All @@ -30,28 +29,29 @@ class ApiClient {
private val fUrl = "https://m.fengshows.com/"

private var okHttpClient = getUnsafeOkHttpClient()
private var gson = Gson()

val yspApiService: YSPApiService by lazy {
Retrofit.Builder()
.baseUrl(yspUrl)
.client(okHttpClient)
.addConverterFactory(GsonConverterFactory.create())
.addConverterFactory(GsonConverterFactory.create(gson))
.build().create(YSPApiService::class.java)
}

val yspTokenService: YSPTokenService by lazy {
Retrofit.Builder()
.baseUrl(myUrl)
.client(okHttpClient)
.addConverterFactory(GsonConverterFactory.create())
.addConverterFactory(GsonConverterFactory.create(gson))
.build().create(YSPTokenService::class.java)
}

val releaseService: ReleaseService by lazy {
Retrofit.Builder()
.baseUrl(HOST)
.client(okHttpClient)
.addConverterFactory(GsonConverterFactory.create())
.addConverterFactory(GsonConverterFactory.create(gson))
.build().create(ReleaseService::class.java)
}

Expand All @@ -67,31 +67,31 @@ class ApiClient {
Retrofit.Builder()
.baseUrl(traceUrl)
.client(okHttpClient)
.addConverterFactory(GsonConverterFactory.create())
.addConverterFactory(GsonConverterFactory.create(gson))
.build().create(YSPBtraceService::class.java)
}

val yspBtraceService2: YSPBtraceService by lazy {
Retrofit.Builder()
.baseUrl(trace2Url)
.client(okHttpClient)
.addConverterFactory(GsonConverterFactory.create())
.addConverterFactory(GsonConverterFactory.create(gson))
.build().create(YSPBtraceService::class.java)
}

val yspToken2Service: YSPApiService by lazy {
Retrofit.Builder()
.baseUrl(tokenUrl)
.client(okHttpClient)
.addConverterFactory(GsonConverterFactory.create())
.addConverterFactory(GsonConverterFactory.create(gson))
.build().create(YSPApiService::class.java)
}

val yspBtraceService3: YSPBtraceService by lazy {
Retrofit.Builder()
.baseUrl(trace3Url)
.client(okHttpClient)
.addConverterFactory(GsonConverterFactory.create())
.addConverterFactory(GsonConverterFactory.create(gson))
.build().create(YSPBtraceService::class.java)
}

Expand All @@ -107,7 +107,7 @@ class ApiClient {
Retrofit.Builder()
.baseUrl(fUrl)
.client(okHttpClient)
.addConverterFactory(GsonConverterFactory.create())
.addConverterFactory(GsonConverterFactory.create(gson))
.build().create(FAuthService::class.java)
}

Expand Down
9 changes: 0 additions & 9 deletions app/src/main/res/layout/player.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,6 @@
android:layout_height="match_parent"
android:background="@color/black"
android:keepScreenOn="true">

<SurfaceView
android:id="@+id/surface_view"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_gravity="center"
app:resize_mode="fill"
app:use_controller="false" />

<androidx.media3.ui.PlayerView
android:id="@+id/player_view"
android:layout_width="match_parent"
Expand Down
2 changes: 1 addition & 1 deletion version.json
Original file line number Diff line number Diff line change
@@ -1 +1 @@
{"version_code": 33556480, "version_name": "v2.0.8"}
{"version_code": 33556736, "version_name": "v2.0.9"}

0 comments on commit bcfca9e

Please sign in to comment.