[Android] Fix switch from audio to video
Geoffrey Métais
git at videolan.org
Thu Dec 6 18:54:39 CET 2018
vlc-android | branch: master | Geoffrey Métais <geoffrey.metais at gmail.com> | Thu Dec 6 18:54:18 2018 +0100| [44f62c05f91a7ff4103e84c5c56d4f08fda48dd3] | committer: Geoffrey Métais
Fix switch from audio to video
> https://code.videolan.org/videolan/vlc-android/commit/44f62c05f91a7ff4103e84c5c56d4f08fda48dd3
---
.../vlc/gui/tv/audioplayer/AudioPlayerActivity.java | 7 ++-----
.../org/videolan/vlc/gui/video/VideoPlayerActivity.java | 4 +---
.../src/org/videolan/vlc/viewmodels/PlaylistModel.kt | 16 +++++++++-------
3 files changed, 12 insertions(+), 15 deletions(-)
diff --git a/vlc-android/src/org/videolan/vlc/gui/tv/audioplayer/AudioPlayerActivity.java b/vlc-android/src/org/videolan/vlc/gui/tv/audioplayer/AudioPlayerActivity.java
index e62c70c87..6da57890e 100644
--- a/vlc-android/src/org/videolan/vlc/gui/tv/audioplayer/AudioPlayerActivity.java
+++ b/vlc-android/src/org/videolan/vlc/gui/tv/audioplayer/AudioPlayerActivity.java
@@ -40,7 +40,6 @@ import org.videolan.vlc.gui.PlaybackServiceActivity;
import org.videolan.vlc.gui.helpers.AudioUtil;
import org.videolan.vlc.gui.helpers.MediaComparators;
import org.videolan.vlc.gui.helpers.UiTools;
-import org.videolan.vlc.gui.preferences.PreferencesActivity;
import org.videolan.vlc.gui.tv.browser.BaseTvActivity;
import org.videolan.vlc.media.MediaUtils;
import org.videolan.vlc.util.AndroidDevices;
@@ -131,9 +130,8 @@ public class AudioPlayerActivity extends BaseTvActivity {
public void update(PlayerState state) {
if (state == null) return;
mBinding.buttonPlay.setImageResource(state.getPlaying() ? R.drawable.ic_pause_w : R.drawable.ic_play_w);
- if (mSettings.getBoolean(PreferencesActivity.VIDEO_RESTORE, false)) {
- mSettings.edit().putBoolean(PreferencesActivity.VIDEO_RESTORE, false).apply();
- model.getCurrentMediaWrapper().removeFlags(MediaWrapper.MEDIA_FORCE_AUDIO);
+ final MediaWrapper mw = model.getCurrentMediaWrapper();
+ if (mw != null && !mw.hasFlag(MediaWrapper.MEDIA_FORCE_AUDIO) && model.canSwitchToVideo()) {
model.switchToVideo();
finish();
return;
@@ -142,7 +140,6 @@ public class AudioPlayerActivity extends BaseTvActivity {
mBinding.mediaArtist.setText(state.getArtist());
mBinding.buttonShuffle.setImageResource(mShuffling ? R.drawable.ic_shuffle_on :
R.drawable.ic_shuffle_w);
- final MediaWrapper mw = model.getCurrentMediaWrapper();
if (mw == null || TextUtils.equals(mCurrentCoverArt, mw.getArtworkMrl())) return;
mCurrentCoverArt = mw.getArtworkMrl();
updateBackground();
diff --git a/vlc-android/src/org/videolan/vlc/gui/video/VideoPlayerActivity.java b/vlc-android/src/org/videolan/vlc/gui/video/VideoPlayerActivity.java
index f5b39f41f..ea5c46b12 100644
--- a/vlc-android/src/org/videolan/vlc/gui/video/VideoPlayerActivity.java
+++ b/vlc-android/src/org/videolan/vlc/gui/video/VideoPlayerActivity.java
@@ -1583,8 +1583,7 @@ public class VideoPlayerActivity extends AppCompatActivity implements IPlaybackS
if (showUI) {
Intent i = new Intent(this, mIsTv ? AudioPlayerActivity.class : MainActivity.class);
startActivity(i);
- } else
- mSettings.edit().putBoolean(PreferencesActivity.VIDEO_RESTORE, true).apply();
+ }
exitOK();
}
@@ -2867,7 +2866,6 @@ public class VideoPlayerActivity extends AppCompatActivity implements IPlaybackS
if (Permissions.checkReadStoragePermission(this, true) && !mSwitchingView)
mHandler.sendEmptyMessage(START_PLAYBACK);
mSwitchingView = false;
- mSettings.edit().putBoolean(PreferencesActivity.VIDEO_RESTORE, false).apply();
if (mService.getVolume() > 100 && !audioBoostEnabled)
mService.setVolume(100);
}
diff --git a/vlc-android/src/org/videolan/vlc/viewmodels/PlaylistModel.kt b/vlc-android/src/org/videolan/vlc/viewmodels/PlaylistModel.kt
index afbe1af9d..9ea9b92a5 100644
--- a/vlc-android/src/org/videolan/vlc/viewmodels/PlaylistModel.kt
+++ b/vlc-android/src/org/videolan/vlc/viewmodels/PlaylistModel.kt
@@ -27,7 +27,6 @@ import kotlinx.coroutines.launch
import org.videolan.medialibrary.Tools
import org.videolan.medialibrary.media.MediaWrapper
import org.videolan.vlc.PlaybackService
-import org.videolan.vlc.gui.preferences.PreferencesActivity
import org.videolan.vlc.media.ABRepeat
import org.videolan.vlc.media.PlaylistManager
import org.videolan.vlc.util.EmptyPBSCallback
@@ -166,17 +165,20 @@ class PlaylistModel : ScopedModel(), PlaybackService.Callback by EmptyPBSCallbac
fun switchToVideo() : Boolean {
service?.apply {
- if (PlaylistManager.hasMedia() && !isVideoPlaying
- && settings.getBoolean(PreferencesActivity.VIDEO_RESTORE, false)) {
- settings.edit().putBoolean(PreferencesActivity.VIDEO_RESTORE, false).apply()
- currentMediaWrapper?.removeFlags(MediaWrapper.MEDIA_FORCE_AUDIO)
- switchToVideo()
- return true
+ if (PlaylistManager.hasMedia() && !isVideoPlaying) {
+ currentMediaWrapper?.run {
+ if (!hasFlag(MediaWrapper.MEDIA_FORCE_AUDIO)) {
+ switchToVideo()
+ return true
+ }
+ }
}
}
return false
}
+ fun canSwitchToVideo() = service?.playlistManager?.player?.canSwitchToVideo() ?: false
+
fun toggleABRepeat() = service?.playlistManager?.toggleABRepeat()
val videoTrackCount
More information about the Android
mailing list