Skip to content

Commit

Permalink
Show user friendly error messages
Browse files Browse the repository at this point in the history
See #309
  • Loading branch information
naveensingh committed Sep 27, 2024
1 parent 43eff34 commit 1edcd5d
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -311,7 +311,7 @@ open class VideoPlayerActivity : SimpleActivity(), SeekBar.OnSeekBarChangeListen
override fun onPlayerErrorChanged(error: PlaybackException?) {
binding.errorMessageHolder.errorMessage.apply {
if (error != null) {
text = error.localizedMessage ?: getString(R.string.failed_to_load_media)
text = error.getFriendlyMessage(context)
setTextColor(if (context.config.blackBackground) Color.WHITE else context.getProperTextColor())
fadeIn()
} else {
Expand Down
23 changes: 23 additions & 0 deletions app/src/main/kotlin/org/fossify/gallery/extensions/Player.kt
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
package org.fossify.gallery.extensions

import android.content.Context
import androidx.media3.common.PlaybackException
import androidx.media3.common.PlaybackException.*
import androidx.media3.common.Player
import org.fossify.gallery.R

fun Player.mute() {
volume = 0f
Expand All @@ -9,3 +13,22 @@ fun Player.mute() {
fun Player.unmute() {
volume = 1f
}

fun PlaybackException.getFriendlyMessage(context: Context): String? {
val resource = when (errorCode) {
ERROR_CODE_PARSING_CONTAINER_MALFORMED,
ERROR_CODE_PARSING_MANIFEST_MALFORMED -> R.string.file_is_malformed_or_corrupted

ERROR_CODE_DECODER_INIT_FAILED,
ERROR_CODE_DECODING_FAILED,
ERROR_CODE_DECODING_FORMAT_EXCEEDS_CAPABILITIES -> R.string.media_exceeds_device_capabilities

ERROR_CODE_PARSING_CONTAINER_UNSUPPORTED,
ERROR_CODE_DECODING_FORMAT_UNSUPPORTED,
ERROR_CODE_PARSING_MANIFEST_UNSUPPORTED -> R.string.unsupported_format

else -> return localizedMessage ?: context.getString(R.string.failed_to_load_media)
}

return context.getString(resource)
}
Original file line number Diff line number Diff line change
Expand Up @@ -452,7 +452,7 @@ class VideoFragment : ViewPagerFragment(), TextureView.SurfaceTextureListener, S
if (error != null) {
binding.videoPreview.beGone()
binding.videoPlayOutline.beGone()
text = error.localizedMessage ?: getString(R.string.failed_to_load_media)
text = error.getFriendlyMessage(context)
setTextColor(if (context.config.blackBackground) Color.WHITE else context.getProperTextColor())
fadeIn()
} else {
Expand Down
7 changes: 6 additions & 1 deletion app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@
<string name="reorder_by_dragging_pro">Reorder folders by dragging (Pro)</string>
<string name="restore_to_path">Restoring to \'%s\'</string>
<string name="full_storage_permission_required">Fossify Gallery needs full access to display all your photos and videos. Go to Settings > Permissions > Photos and videos > Allow all.</string>
<string name="failed_to_load_media">Failed to load media.</string>

<!-- Filter -->
<string name="filter_media">Filter media</string>
Expand Down Expand Up @@ -242,6 +241,12 @@
<string name="toggle_favorite">Toggle favorite</string>
<string name="toggle_file_visibility">Toggle file visibility</string>

<!-- Errors -->
<string name="failed_to_load_media">Failed to load media.</string>
<string name="file_is_malformed_or_corrupted">File is malformed or corrupted.</string>
<string name="media_exceeds_device_capabilities">Media exceeds device capabilities.</string>
<string name="unsupported_format">Unsupported format.</string>

<!-- FAQ -->
<string name="faq_1_title">How can I make Fossify Gallery the default device gallery?</string>
<string name="faq_1_text">First you have to find the currently default gallery in the Apps section of your device settings, look for a button that says something like \"Open by default\", click on it, then select \"Clear defaults\".
Expand Down

0 comments on commit 1edcd5d

Please sign in to comment.