[Android] LibVLC: enable Video if surface are attached while playing
Thomas Guillem
git at videolan.org
Thu Jul 23 09:58:02 CEST 2015
vlc-ports/android | branch: master | Thomas Guillem <thomas at gllm.fr> | Thu Jul 23 09:56:09 2015 +0200| [d2460db5add0227e61c2c3a54f6713093e60a9c8] | committer: Thomas Guillem
LibVLC: enable Video if surface are attached while playing
Move the logic from the application to the lib.
> http://git.videolan.org/gitweb.cgi/vlc-ports/android.git/?a=commit;h=d2460db5add0227e61c2c3a54f6713093e60a9c8
---
libvlc/src/org/videolan/libvlc/MediaPlayer.java | 24 +++++++++++++++++++-
.../src/org/videolan/vlc/PlaybackService.java | 23 +------------------
2 files changed, 24 insertions(+), 23 deletions(-)
diff --git a/libvlc/src/org/videolan/libvlc/MediaPlayer.java b/libvlc/src/org/videolan/libvlc/MediaPlayer.java
index 9048dab..a556707 100644
--- a/libvlc/src/org/videolan/libvlc/MediaPlayer.java
+++ b/libvlc/src/org/videolan/libvlc/MediaPlayer.java
@@ -325,12 +325,17 @@ public class MediaPlayer extends VLCObject<MediaPlayer.Event> {
@Override
public void onSurfacesCreated(AWindow vout) {
boolean play = false;
+ boolean enableVideo = false;
synchronized (MediaPlayer.this) {
if (!mPlaying && mPlayRequested)
play = true;
+ else if (mVoutCount == 0)
+ enableVideo = true;
}
if (play)
play();
+ else if (enableVideo)
+ setVideoTrackEnabled(true);
}
@Override
@@ -341,7 +346,7 @@ public class MediaPlayer extends VLCObject<MediaPlayer.Event> {
disableVideo = true;
}
if (disableVideo)
- setVideoTrack(-1);
+ setVideoTrackEnabled(false);
synchronized (MediaPlayer.this) {
/* Wait for Vout destruction (mVoutCount = 0) in order to be sure that the surface is not
* used after leaving this callback. This shouldn't be needed when using MediaCodec or
@@ -547,6 +552,23 @@ public class MediaPlayer extends VLCObject<MediaPlayer.Event> {
return nativeSetVideoTrack(index);
}
+ private void setVideoTrackEnabled(boolean enabled) {
+ if (!enabled) {
+ setVideoTrack(-1);
+ } else {
+ final MediaPlayer.TrackDescription tracks[] = getVideoTracks();
+
+ if (tracks != null) {
+ for (MediaPlayer.TrackDescription track : tracks) {
+ if (track.id != -1) {
+ setVideoTrack(track.id);
+ break;
+ }
+ }
+ }
+ }
+ }
+
/**
* Get the number of available audio tracks.
*/
diff --git a/vlc-android/src/org/videolan/vlc/PlaybackService.java b/vlc-android/src/org/videolan/vlc/PlaybackService.java
index ae3713f..ac8731a 100644
--- a/vlc-android/src/org/videolan/vlc/PlaybackService.java
+++ b/vlc-android/src/org/videolan/vlc/PlaybackService.java
@@ -749,24 +749,6 @@ public class PlaybackService extends Service implements IVLCVout.Callback {
}
};
- private void setVideoTrackEnabled(boolean enabled) {
- if (!enabled) {
- mMediaPlayer.setVideoTrack(-1);
- } else {
- final MediaPlayer.TrackDescription tracks[] = mMediaPlayer.getVideoTracks();
-
- if (tracks != null) {
- for (MediaPlayer.TrackDescription track : tracks) {
- if (track.id != -1) {
- mMediaPlayer.setVideoTrack(track.id);
- break;
- }
- }
- }
- }
- }
-
-
public boolean canSwitchToVideo() {
return hasCurrentMedia() && mMediaPlayer.getVideoTracksCount() > 0;
}
@@ -775,13 +757,10 @@ public class PlaybackService extends Service implements IVLCVout.Callback {
if (!canSwitchToVideo() || !mMediaPlayer.isPlaying())
return false;
if (mMediaPlayer.getVLCVout().areViewsAttached()) {
- setVideoTrackEnabled(true);
hideNotification(false);
return true;
- } else {
- setVideoTrackEnabled(false);
+ } else
return false;
- }
}
@MainThread
More information about the Android
mailing list