[Android] AudioPlayer: switch to video automatically
Thomas Guillem
git at videolan.org
Fri Jul 10 20:34:43 CEST 2015
vlc-ports/android | branch: master | Thomas Guillem <thomas at gllm.fr> | Fri Jul 10 19:19:51 2015 +0200| [64358e7fc3165129f4a8f6a7272e7fbb43a54ced] | committer: Thomas Guillem
AudioPlayer: switch to video automatically
If the playing file is a video and not played as audio, switch to video mode,
do it only one time.
> http://git.videolan.org/gitweb.cgi/vlc-ports/android.git/?a=commit;h=64358e7fc3165129f4a8f6a7272e7fbb43a54ced
---
vlc-android/src/org/videolan/vlc/MediaWrapper.java | 3 +++
.../src/org/videolan/vlc/gui/audio/AudioPlayer.java | 16 ++++++++++++++++
.../videolan/vlc/gui/browser/BaseBrowserAdapter.java | 3 +++
.../videolan/vlc/gui/browser/BaseBrowserFragment.java | 5 ++++-
.../org/videolan/vlc/gui/video/VideoGridFragment.java | 6 +++++-
.../videolan/vlc/gui/video/VideoPlayerActivity.java | 1 +
vlc-android/src/org/videolan/vlc/util/VLCOptions.java | 1 +
7 files changed, 33 insertions(+), 2 deletions(-)
diff --git a/vlc-android/src/org/videolan/vlc/MediaWrapper.java b/vlc-android/src/org/videolan/vlc/MediaWrapper.java
index d2e36e5..5e8401c 100644
--- a/vlc-android/src/org/videolan/vlc/MediaWrapper.java
+++ b/vlc-android/src/org/videolan/vlc/MediaWrapper.java
@@ -430,6 +430,9 @@ public class MediaWrapper implements Parcelable {
public int getFlags() {
return mFlags;
}
+ public void removeFlags(int flags) {
+ mFlags &= ~flags;
+ }
@Override
public int describeContents() {
diff --git a/vlc-android/src/org/videolan/vlc/gui/audio/AudioPlayer.java b/vlc-android/src/org/videolan/vlc/gui/audio/AudioPlayer.java
index f5d98ec..b9b2007 100644
--- a/vlc-android/src/org/videolan/vlc/gui/audio/AudioPlayer.java
+++ b/vlc-android/src/org/videolan/vlc/gui/audio/AudioPlayer.java
@@ -64,6 +64,7 @@ import org.videolan.vlc.gui.dialogs.AdvOptionsDialog;
import org.videolan.vlc.gui.dialogs.SavePlaylistDialog;
import org.videolan.vlc.util.Strings;
import org.videolan.vlc.util.Util;
+import org.videolan.vlc.util.VLCOptions;
import org.videolan.vlc.widget.AudioMediaSwitcher.AudioMediaSwitcherListener;
import java.util.ArrayList;
@@ -94,6 +95,7 @@ public class AudioPlayer extends PlaybackServiceFragment implements PlaybackServ
private boolean mShowRemainingTime = false;
private boolean mPreviewingSeek = false;
+ private boolean mSwitchedToVideo = false;
private AudioPlaylistAdapter mSongsListAdapter;
@@ -167,6 +169,7 @@ public class AudioPlayer extends PlaybackServiceFragment implements PlaybackServ
public void onClick(View v) {
if (mService != null) {
mService.switchToVideo();
+ mSwitchedToVideo = true;
}
}
});
@@ -328,6 +331,7 @@ public class AudioPlayer extends PlaybackServiceFragment implements PlaybackServ
if (mSettings.getBoolean(PreferencesActivity.VIDEO_RESTORE, false)){
Util.commitPreferences(mSettings.edit().putBoolean(PreferencesActivity.VIDEO_RESTORE, false));
mService.switchToVideo();
+ mSwitchedToVideo = true;
return;
} else
show();
@@ -416,6 +420,18 @@ public class AudioPlayer extends PlaybackServiceFragment implements PlaybackServ
@Override
public void onMediaPlayerEvent(MediaPlayer.Event event) {
+ switch (event.type) {
+ case MediaPlayer.Event.Opening:
+ mSwitchedToVideo = false;
+ break;
+ case MediaPlayer.Event.ESAdded:
+ final boolean forceAudio = (mService.getCurrentMediaWrapper().getFlags() & VLCOptions.MEDIA_FORCE_AUDIO) != 0;
+ if (!forceAudio && !mSwitchedToVideo && event.getEsChangedType() == Media.Track.Type.Video) {
+ mService.switchToVideo();
+ mSwitchedToVideo = true;
+ }
+ break;
+ }
}
private void updateList() {
diff --git a/vlc-android/src/org/videolan/vlc/gui/browser/BaseBrowserAdapter.java b/vlc-android/src/org/videolan/vlc/gui/browser/BaseBrowserAdapter.java
index 4e887f5..1847bf3 100644
--- a/vlc-android/src/org/videolan/vlc/gui/browser/BaseBrowserAdapter.java
+++ b/vlc-android/src/org/videolan/vlc/gui/browser/BaseBrowserAdapter.java
@@ -41,6 +41,7 @@ import org.videolan.vlc.gui.audio.MediaComparators;
import org.videolan.vlc.util.CustomDirectories;
import org.videolan.vlc.util.Strings;
import org.videolan.vlc.util.Util;
+import org.videolan.vlc.util.VLCOptions;
import java.io.File;
import java.util.ArrayList;
@@ -116,6 +117,8 @@ public class BaseBrowserAdapter extends RecyclerView.Adapter<RecyclerView.ViewH
@Override
public void onClick(View v) {
MediaWrapper mw = (MediaWrapper) getItem(holder.getAdapterPosition());
+ mw.removeFlags(VLCOptions.MEDIA_FORCE_AUDIO);
+
if (mw.getType() == MediaWrapper.TYPE_DIR)
fragment.browse(mw, holder.getAdapterPosition(), true);
else if (mw.getType() == MediaWrapper.TYPE_VIDEO)
diff --git a/vlc-android/src/org/videolan/vlc/gui/browser/BaseBrowserFragment.java b/vlc-android/src/org/videolan/vlc/gui/browser/BaseBrowserFragment.java
index 19aa191..e6cffc8 100644
--- a/vlc-android/src/org/videolan/vlc/gui/browser/BaseBrowserFragment.java
+++ b/vlc-android/src/org/videolan/vlc/gui/browser/BaseBrowserFragment.java
@@ -59,6 +59,7 @@ import org.videolan.vlc.gui.video.VideoPlayerActivity;
import org.videolan.vlc.interfaces.IRefreshable;
import org.videolan.vlc.util.Util;
import org.videolan.vlc.util.VLCInstance;
+import org.videolan.vlc.util.VLCOptions;
import org.videolan.vlc.util.VLCRunnable;
import org.videolan.vlc.util.WeakHandler;
import org.videolan.vlc.widget.ContextMenuRecyclerView;
@@ -419,7 +420,8 @@ public abstract class BaseBrowserFragment extends MediaBrowserFragment implement
MediaWrapper mw = (MediaWrapper) mAdapter.getItem(position);
switch (id){
case R.id.directory_view_play:
- Util.openMedia(getActivity(), (MediaWrapper) mAdapter.getItem(position));
+ mw.removeFlags(VLCOptions.MEDIA_FORCE_AUDIO);
+ Util.openMedia(getActivity(), mw);
return true;
case R.id.directory_view_append: {
if (mService != null)
@@ -445,6 +447,7 @@ public abstract class BaseBrowserFragment extends MediaBrowserFragment implement
return true;
case R.id.directory_view_play_audio: {
if (mService != null) {
+ mw.addFlags(VLCOptions.MEDIA_FORCE_AUDIO);
mService.load(mw);
}
return true;
diff --git a/vlc-android/src/org/videolan/vlc/gui/video/VideoGridFragment.java b/vlc-android/src/org/videolan/vlc/gui/video/VideoGridFragment.java
index 8c0c1be..e11a515 100644
--- a/vlc-android/src/org/videolan/vlc/gui/video/VideoGridFragment.java
+++ b/vlc-android/src/org/videolan/vlc/gui/video/VideoGridFragment.java
@@ -71,6 +71,7 @@ import org.videolan.vlc.interfaces.IVideoBrowser;
import org.videolan.vlc.util.AndroidDevices;
import org.videolan.vlc.util.Util;
import org.videolan.vlc.util.VLCInstance;
+import org.videolan.vlc.util.VLCOptions;
import org.videolan.vlc.util.WeakHandler;
import org.videolan.vlc.widget.SwipeRefreshLayout;
@@ -297,12 +298,15 @@ public class VideoGridFragment extends MediaBrowserFragment implements ISortable
}
protected void playVideo(MediaWrapper media, boolean fromStart) {
+ media.removeFlags(VLCOptions.MEDIA_FORCE_AUDIO);
VideoPlayerActivity.start(getActivity(), media.getUri(), fromStart);
}
protected void playAudio(MediaWrapper media) {
- if (mService != null)
+ if (mService != null) {
+ media.addFlags(VLCOptions.MEDIA_FORCE_AUDIO);
mService.load(media);
+ }
}
private boolean handleContextItemSelected(MenuItem menu, int position) {
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 40d34d0..7dcb62e 100644
--- a/vlc-android/src/org/videolan/vlc/gui/video/VideoPlayerActivity.java
+++ b/vlc-android/src/org/videolan/vlc/gui/video/VideoPlayerActivity.java
@@ -2598,6 +2598,7 @@ public class VideoPlayerActivity extends AppCompatActivity implements IVLCVout.C
mw.addFlags(VLCOptions.MEDIA_PAUSED);
if (mHardwareAccelerationError)
mw.addFlags(VLCOptions.MEDIA_NO_HWACCEL);
+ mw.removeFlags(VLCOptions.MEDIA_FORCE_AUDIO);
mw.addFlags(VLCOptions.MEDIA_VIDEO);
mService.addCallback(this);
mService.load(mw);
diff --git a/vlc-android/src/org/videolan/vlc/util/VLCOptions.java b/vlc-android/src/org/videolan/vlc/util/VLCOptions.java
index 9b8d308..50d1394 100644
--- a/vlc-android/src/org/videolan/vlc/util/VLCOptions.java
+++ b/vlc-android/src/org/videolan/vlc/util/VLCOptions.java
@@ -52,6 +52,7 @@ public class VLCOptions {
public final static int MEDIA_VIDEO = 0x01;
public final static int MEDIA_NO_HWACCEL = 0x02;
public final static int MEDIA_PAUSED = 0x4;
+ public final static int MEDIA_FORCE_AUDIO = 0x8;
public static ArrayList<String> getLibOptions(Context context) {
final SharedPreferences pref = PreferenceManager.getDefaultSharedPreferences(context);
More information about the Android
mailing list