Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Display custom message for Error code 4001 #239

Open
wants to merge 7 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ internal fun PlaybackException.getErrorMessage(playerId: String): String {
PlaybackException.ERROR_CODE_IO_NETWORK_CONNECTION_FAILED -> "Oops! It seems like you're not connected to the internet. Please check your connection and try again.\n Player code: ${this.errorCode}. Player Id: $playerId"
PlaybackException.ERROR_CODE_IO_NETWORK_CONNECTION_TIMEOUT -> "The request took too long to process due to a slow or unstable network connection. Please try again.\n Player code: ${this.errorCode}. Player Id: $playerId"
PlaybackException.ERROR_CODE_DRM_LICENSE_ACQUISITION_FAILED -> "There was an issue fetching the license key for this video. Please try again later.\n Player code: ${this.errorCode}. Player Id: $playerId"
PlaybackException.ERROR_CODE_DECODER_INIT_FAILED -> "<html><body><p>An error occurred while playing the video. Try restarting your device or playing another video. More help <a href='https://tpstreams.com/help/troubleshooting-steps-for-error-code-4001'>click here</a>.<br> Player code: ${this.errorCode}. Player Id: $playerId</p></body></html>"
else -> "Oops! Something went wrong. Please contact support for assistance and provide details about the issue.\n Player code: ${this.errorCode}. Player Id: $playerId"
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,16 @@ package com.tpstream.player.ui
import android.app.Dialog
import android.content.pm.ActivityInfo
import android.media.MediaCodec
import android.os.Build
import android.os.Bundle
import android.text.Html
import android.text.method.LinkMovementMethod
import android.util.Log
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.ImageButton
import android.widget.TextView
import androidx.core.content.ContextCompat
import androidx.fragment.app.Fragment
import com.tpstream.player.*
Expand Down Expand Up @@ -395,7 +399,24 @@ class TpStreamPlayerFragment : Fragment(), DownloadCallback.Listener {
private fun showErrorMessage(message: String) {
if ([email protected]) return
viewBinding.errorMessage.visibility = View.VISIBLE
viewBinding.errorMessage.text = message
if (isDecoderError(message)) {
viewBinding.errorMessage.setHtmlText(message)
} else {
viewBinding.errorMessage.text = message
}
}

private fun isDecoderError(message: String): Boolean {
return listOf("4001", "4003").any { message.contains(it) }
}

private fun TextView.setHtmlText(message: String) {
movementMethod = LinkMovementMethod.getInstance()
text = if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
Html.fromHtml(message, Html.FROM_HTML_MODE_LEGACY)
} else {
Html.fromHtml(message)
}
}

private val tpStreamPlayerImplCallBack = object :TpStreamPlayerImplCallBack{
Expand Down
1 change: 1 addition & 0 deletions player/src/main/res/layout/fragment_tp_stream_player.xml
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
android:layout_gravity="center"
android:textStyle="bold"
android:visibility="gone"
android:padding="32dp"
android:textAlignment="center"
android:textSize="14dp"
android:text=""/>
Expand Down
Loading