Compare commits

...

5 Commits

26 changed files with 77 additions and 34 deletions
@@ -319,7 +319,11 @@ class UIDialogs {
closeAction?.invoke()
}, UIDialogs.ActionStyle.NONE),
UIDialogs.Action(context.getString(R.string.retry), {
retryAction?.invoke();
try {
retryAction?.invoke();
} catch (e: Throwable) {
Logger.e(TAG, "Unhandled exception retrying", e)
}
}, UIDialogs.ActionStyle.PRIMARY)
);
else
@@ -333,7 +337,11 @@ class UIDialogs {
closeAction?.invoke()
}, UIDialogs.ActionStyle.NONE),
UIDialogs.Action(context.getString(R.string.retry), {
retryAction?.invoke();
try {
retryAction?.invoke();
} catch (e: Throwable) {
Logger.e(TAG, "Unhandled exception retrying", e)
}
}, UIDialogs.ActionStyle.PRIMARY)
);
}
@@ -108,7 +108,7 @@ abstract class CastingDevice {
val expectedCurrentTime: Double
get() {
val diff = (System.currentTimeMillis() - lastTimeChangeTime_ms).toDouble() / 1000.0;
val diff = if (isPlaying) ((System.currentTimeMillis() - lastTimeChangeTime_ms).toDouble() / 1000.0) else 0.0;
return time + diff;
};
var connectionState: CastConnectionState = CastConnectionState.DISCONNECTED
@@ -344,6 +344,10 @@ class ChromecastCastingDevice : CastingDevice {
//Connection loop
while (_scopeIO?.isActive == true) {
_sessionId = null;
_launchRetries = 0
_mediaSessionId = null;
Logger.i(TAG, "Connecting to Chromecast.");
connectionState = CastConnectionState.CONNECTING;
@@ -499,6 +503,10 @@ class ChromecastCastingDevice : CastingDevice {
}
} catch (e: Throwable) {
Logger.w(TAG, "Failed to send channel message (sourceId: $sourceId, destinationId: $destinationId, namespace: $namespace, json: $json)", e);
_socket?.close();
Logger.i(TAG, "Socket disconnected.");
connectionState = CastConnectionState.CONNECTING;
}
}
@@ -600,7 +608,7 @@ class ChromecastCastingDevice : CastingDevice {
}
isPlaying = playerState == "PLAYING";
if (isPlaying) {
if (isPlaying || playerState == "PAUSED") {
setTime(currentTime);
}
@@ -82,7 +82,11 @@ class TaskHandler<TParameter, TResult> {
handled = true;
} catch (e: Throwable) {
Logger.w(TAG, "Handled exception in TaskHandler onSuccess.", e);
onError.emit(e, parameter);
try {
onError.emit(e, parameter);
} catch (e: Throwable) {
Logger.e(TAG, "Unhandled exception in .exception handler 1", e)
}
handled = true;
}
}
@@ -99,10 +103,14 @@ class TaskHandler<TParameter, TResult> {
if (id != _idGenerator)
return@withContext;
if (!onError.emit(e, parameter)) {
Logger.e(TAG, "Uncaught exception handled by TaskHandler.", e);
} else {
//Logger.w(TAG, "Handled exception in TaskHandler invoke.", e); (Prevents duplicate logs)
try {
if (!onError.emit(e, parameter)) {
Logger.e(TAG, "Uncaught exception handled by TaskHandler.", e);
} else {
//Logger.w(TAG, "Handled exception in TaskHandler invoke.", e); (Prevents duplicate logs)
}
} catch (e: Throwable) {
Logger.e(TAG, "Unhandled exception in .exception handler 2", e)
}
}
}
@@ -619,6 +619,7 @@ class VideoDetailView : ConstraintLayout {
loadCurrentVideo(lastPositionMilliseconds);
updatePillButtonVisibilities();
setCastEnabled(false);
}
else -> {}
}
@@ -647,6 +648,15 @@ class VideoDetailView : ConstraintLayout {
_timeBar.setDuration(video?.duration ?: 0);
}
};
_cast.onTimeJobTimeChanged_s.subscribe {
if (_isCasting) {
setLastPositionMilliseconds((it * 1000.0).toLong(), true);
_timeBar.setPosition(it);
_timeBar.setBufferedPosition(0);
_timeBar.setDuration(video?.duration ?: 0);
}
}
}
_playerProgress.player = _player.exoPlayer?.player;
@@ -10,10 +10,11 @@ class ItemMoveCallback : ItemTouchHelper.Callback {
var onRowMoved = Event2<Int, Int>();
var onRowSelected = Event1<ViewHolder>();
var onRowClear = Event1<ViewHolder>();
var canEdit = true
constructor() : super() { }
override fun isLongPressDragEnabled(): Boolean { return true; }
override fun isLongPressDragEnabled(): Boolean { return canEdit; }
override fun isItemViewSwipeEnabled(): Boolean { return false; }
override fun getMovementFlags(recyclerView: RecyclerView, viewHolder: RecyclerView.ViewHolder): Int {
@@ -21,10 +21,13 @@ import com.futo.platformplayer.R
import com.futo.platformplayer.api.media.models.chapters.IChapter
import com.futo.platformplayer.api.media.models.video.IPlatformVideoDetails
import com.futo.platformplayer.casting.AirPlayCastingDevice
import com.futo.platformplayer.casting.ChromecastCastingDevice
import com.futo.platformplayer.casting.StateCasting
import com.futo.platformplayer.constructs.Event0
import com.futo.platformplayer.constructs.Event1
import com.futo.platformplayer.constructs.Event2
import com.futo.platformplayer.formatDuration
import com.futo.platformplayer.states.StateHistory
import com.futo.platformplayer.states.StatePlayer
import com.futo.platformplayer.views.behavior.GestureControlView
import kotlinx.coroutines.CoroutineScope
@@ -61,6 +64,7 @@ class CastView : ConstraintLayout {
val onSettingsClick = Event0();
val onPrevious = Event0();
val onNext = Event0();
val onTimeJobTimeChanged_s = Event1<Long>()
@OptIn(UnstableApi::class)
constructor(context: Context, attrs: AttributeSet) : super(context, attrs) {
@@ -185,11 +189,11 @@ class CastView : ConstraintLayout {
}
fun setIsPlaying(isPlaying: Boolean) {
_updateTimeJob?.cancel();
stopTimeJob()
if(isPlaying) {
val d = StateCasting.instance.activeDevice;
if (d is AirPlayCastingDevice) {
if (d is AirPlayCastingDevice || d is ChromecastCastingDevice) {
_updateTimeJob = _scope.launch {
while (true) {
val device = StateCasting.instance.activeDevice;
@@ -198,7 +202,9 @@ class CastView : ConstraintLayout {
}
delay(1000);
setTime((device.expectedCurrentTime * 1000.0).toLong());
val time_ms = (device.expectedCurrentTime * 1000.0).toLong()
setTime(time_ms);
onTimeJobTimeChanged_s.emit(device.expectedCurrentTime.toLong())
}
}
}
@@ -26,6 +26,7 @@ class VideoListEditorView : FrameLayout {
val onVideoOptions = Event1<IPlatformVideo>();
val onVideoClicked = Event1<IPlatformVideo>();
val isEmpty get() = _videos.isEmpty();
val itemMoveCallback: ItemMoveCallback
constructor(context: Context, attrs: AttributeSet? = null) : super(context, attrs) {
val recyclerPlaylist = RecyclerView(context, attrs);
@@ -34,14 +35,14 @@ class VideoListEditorView : FrameLayout {
recyclerPlaylist.layoutParams = LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT);
addView(recyclerPlaylist);
val callback = ItemMoveCallback();
val touchHelper = ItemTouchHelper(callback);
itemMoveCallback = ItemMoveCallback();
val touchHelper = ItemTouchHelper(itemMoveCallback);
val adapterVideos = VideoListEditorAdapter(touchHelper);
recyclerPlaylist.adapter = adapterVideos;
recyclerPlaylist.layoutManager = LinearLayoutManager(context);
touchHelper.attachToRecyclerView(recyclerPlaylist);
callback.onRowMoved.subscribe { fromPosition, toPosition ->
itemMoveCallback.onRowMoved.subscribe { fromPosition, toPosition ->
synchronized(_videos) {
if (fromPosition < toPosition) {
for (i in fromPosition until toPosition)
@@ -94,6 +95,7 @@ class VideoListEditorView : FrameLayout {
synchronized(_videos) {
_videos.clear();
_videos.addAll(videos ?: listOf());
itemMoveCallback.canEdit = canEdit
_adapterVideos?.setVideos(_videos, canEdit);
}
}