Commit dd65488e authored by Geoffrey Métais's avatar Geoffrey Métais

Restart mediaplayer on error

parent bf6ea964
......@@ -586,4 +586,5 @@
<string name="browser_storages">Storages</string>
<string name="msg_delete_failed">Failed to delete media %1$s</string>
<string name="renderer_list_title">Displays</string>
<string name="feedback_player_crashed">Sorry, VLC just crashed. Please try again.</string>
</resources>
......@@ -3,11 +3,15 @@ package org.videolan.vlc.media
import android.net.Uri
import android.support.annotation.MainThread
import android.support.v4.media.session.PlaybackStateCompat
import android.widget.Toast
import kotlinx.coroutines.experimental.CoroutineExceptionHandler
import kotlinx.coroutines.experimental.android.UI
import kotlinx.coroutines.experimental.async
import kotlinx.coroutines.experimental.launch
import kotlinx.coroutines.experimental.newSingleThreadContext
import org.videolan.libvlc.*
import org.videolan.medialibrary.media.MediaWrapper
import org.videolan.vlc.R
import org.videolan.vlc.RendererDelegate
import org.videolan.vlc.VLCApplication
import org.videolan.vlc.gui.preferences.PreferencesActivity
......@@ -17,6 +21,7 @@ import org.videolan.vlc.util.VLCOptions
@Suppress("EXPERIMENTAL_FEATURE_WARNING")
class PlayerController : IVLCVout.Callback, MediaPlayer.EventListener {
private val exceptionHandler by lazy(LazyThreadSafetyMode.NONE) { CoroutineExceptionHandler { _, _ -> onPlayerError() } }
private val playerContext by lazy(LazyThreadSafetyMode.NONE) { newSingleThreadContext("vlc-player") }
private val settings by lazy(LazyThreadSafetyMode.NONE) { VLCApplication.getSettings() }
......@@ -58,7 +63,7 @@ class PlayerController : IVLCVout.Callback, MediaPlayer.EventListener {
mediaplayerEventListener = listener
seekable = true
pausable = true
launch(playerContext) {
launch(playerContext+exceptionHandler) {
mediaplayer.media = media
}.join()
mediaplayer.setEventListener(this@PlayerController)
......@@ -230,7 +235,7 @@ class PlayerController : IVLCVout.Callback, MediaPlayer.EventListener {
suspend fun expand(): MediaList? {
return mediaplayer.media?.let {
mediaplayer.setEventListener(null)
val ml = async { it.subItems() }.await()
val ml = async(playerContext+exceptionHandler) { it.subItems() }.await()
it.release()
mediaplayer.setEventListener(this@PlayerController)
return ml
......@@ -250,4 +255,11 @@ class PlayerController : IVLCVout.Callback, MediaPlayer.EventListener {
}
mediaplayerEventListener?.onEvent(event)
}
private fun onPlayerError() {
launch(UI) {
restart()
Toast.makeText(VLCApplication.getAppContext(), VLCApplication.getAppContext().getString(R.string.feedback_player_crashed), Toast.LENGTH_LONG).show()
}
}
}
\ No newline at end of file
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment