Commit 925e8b83 authored by Adrien Maglo's avatar Adrien Maglo
Browse files

VideoPlayerActivity: switch to audio mode when an audio file is opened from an...

VideoPlayerActivity: switch to audio mode when an audio file is opened from an external application.

close #10020
parent 3a892c62
...@@ -370,7 +370,6 @@ void Java_org_videolan_libvlc_LibVLC_playMRL(JNIEnv *env, jobject thiz, jlong in ...@@ -370,7 +370,6 @@ void Java_org_videolan_libvlc_LibVLC_playMRL(JNIEnv *env, jobject thiz, jlong in
for(int i = 0; i < (sizeof(mp_events) / sizeof(*mp_events)); i++) for(int i = 0; i < (sizeof(mp_events) / sizeof(*mp_events)); i++)
libvlc_event_attach(ev, mp_events[i], vlc_event_callback, myVm); libvlc_event_attach(ev, mp_events[i], vlc_event_callback, myVm);
/* Keep a pointer to this media player */ /* Keep a pointer to this media player */
setLong(env, thiz, "mInternalMediaPlayerInstance", (jlong)(intptr_t)mp); setLong(env, thiz, "mInternalMediaPlayerInstance", (jlong)(intptr_t)mp);
...@@ -396,6 +395,14 @@ void Java_org_videolan_libvlc_LibVLC_playMRL(JNIEnv *env, jobject thiz, jlong in ...@@ -396,6 +395,14 @@ void Java_org_videolan_libvlc_LibVLC_playMRL(JNIEnv *env, jobject thiz, jlong in
(*env)->ReleaseStringUTFChars(env, mrl, p_mrl); (*env)->ReleaseStringUTFChars(env, mrl, p_mrl);
/* Connect the media event manager. */
libvlc_event_manager_t *ev_media = libvlc_media_event_manager(p_md);
static const libvlc_event_type_t mp_media_events[] = {
libvlc_MediaParsedChanged
};
for(int i = 0; i < (sizeof(mp_media_events) / sizeof(*mp_media_events)); i++)
libvlc_event_attach(ev_media, mp_media_events[i], vlc_event_callback, myVm);
libvlc_media_player_set_media(mp, p_md); libvlc_media_player_set_media(mp, p_md);
libvlc_media_player_play(mp); libvlc_media_player_play(mp);
} }
......
...@@ -35,7 +35,7 @@ public class EventHandler { ...@@ -35,7 +35,7 @@ public class EventHandler {
//public static final int MediaMetaChanged = 0; //public static final int MediaMetaChanged = 0;
//public static final int MediaSubItemAdded = 1; //public static final int MediaSubItemAdded = 1;
//public static final int MediaDurationChanged = 2; //public static final int MediaDurationChanged = 2;
//public static final int MediaParsedChanged = 3; public static final int MediaParsedChanged = 3;
//public static final int MediaFreed = 4; //public static final int MediaFreed = 4;
//public static final int MediaStateChanged = 5; //public static final int MediaStateChanged = 5;
......
...@@ -401,6 +401,9 @@ public class AudioService extends Service { ...@@ -401,6 +401,9 @@ public class AudioService extends Service {
if(service == null) return; if(service == null) return;
switch (msg.getData().getInt("event")) { switch (msg.getData().getInt("event")) {
case EventHandler.MediaParsedChanged:
Log.i(TAG, "MediaParsedChanged");
break;
case EventHandler.MediaPlayerPlaying: case EventHandler.MediaPlayerPlaying:
Log.i(TAG, "MediaPlayerPlaying"); Log.i(TAG, "MediaPlayerPlaying");
service.executeUpdate(); service.executeUpdate();
......
...@@ -51,6 +51,7 @@ import org.videolan.vlc.VLCApplication; ...@@ -51,6 +51,7 @@ import org.videolan.vlc.VLCApplication;
import org.videolan.vlc.WeakHandler; import org.videolan.vlc.WeakHandler;
import org.videolan.vlc.gui.CommonDialogs; import org.videolan.vlc.gui.CommonDialogs;
import org.videolan.vlc.gui.CommonDialogs.MenuType; import org.videolan.vlc.gui.CommonDialogs.MenuType;
import org.videolan.vlc.gui.MainActivity;
import org.videolan.vlc.gui.PreferencesActivity; import org.videolan.vlc.gui.PreferencesActivity;
import android.annotation.TargetApi; import android.annotation.TargetApi;
...@@ -747,8 +748,17 @@ public class VideoPlayerActivity extends Activity implements IVideoPlayer { ...@@ -747,8 +748,17 @@ public class VideoPlayerActivity extends Activity implements IVideoPlayer {
public void handleMessage(Message msg) { public void handleMessage(Message msg) {
VideoPlayerActivity activity = getOwner(); VideoPlayerActivity activity = getOwner();
if(activity == null) return; if(activity == null) return;
// Do not handle events if we are leaving the VideoPlayerActivity
if (activity.mSwitchingView) return;
switch (msg.getData().getInt("event")) { switch (msg.getData().getInt("event")) {
case EventHandler.MediaParsedChanged:
Log.i(TAG, "MediaParsedChanged");
if (activity.mLibVLC.getVideoTracksCount() < 1) {
Log.i(TAG, "No video track, open in audio mode");
activity.switchToAudioMode();
}
break;
case EventHandler.MediaPlayerPlaying: case EventHandler.MediaPlayerPlaying:
Log.i(TAG, "MediaPlayerPlaying"); Log.i(TAG, "MediaPlayerPlaying");
activity.showOverlay(); activity.showOverlay();
...@@ -904,6 +914,17 @@ public class VideoPlayerActivity extends Activity implements IVideoPlayer { ...@@ -904,6 +914,17 @@ public class VideoPlayerActivity extends Activity implements IVideoPlayer {
} }
} }
private void switchToAudioMode() {
mSwitchingView = true;
// Show the MainActivity if it is not in background.
if (getIntent().getAction() != null
&& getIntent().getAction().equals(Intent.ACTION_VIEW)) {
Intent i = new Intent(this, MainActivity.class);
startActivity(i);
}
finish();
}
private void changeSurfaceSize() { private void changeSurfaceSize() {
int sw; int sw;
int sh; int sh;
......
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