Commit abfa12b0 authored by Sébastien Toque's avatar Sébastien Toque

Audio track selection for multi-track audio files

parent 19ccff83
...@@ -719,6 +719,48 @@ jint Java_org_videolan_vlc_LibVLC_getAudioTracksCount(JNIEnv *env, jobject thiz) ...@@ -719,6 +719,48 @@ jint Java_org_videolan_vlc_LibVLC_getAudioTracksCount(JNIEnv *env, jobject thiz)
return -1; return -1;
} }
jobjectArray Java_org_videolan_vlc_LibVLC_getAudioTrackDescription(JNIEnv *env, jobject thiz)
{
libvlc_media_player_t *mp = getMediaPlayer(env, thiz);
if (!mp)
return NULL;
int i_nbTracks = libvlc_audio_get_track_count(mp) - 1;
if (i_nbTracks < 0)
i_nbTracks = 0;
jobjectArray array = (*env)->NewObjectArray(env, i_nbTracks,
(*env)->FindClass(env, "java/lang/String"),
NULL);
libvlc_track_description_t *first = libvlc_audio_get_track_description(mp);
libvlc_track_description_t *desc = first != NULL ? first->p_next : NULL;
unsigned i;
for (i = 0; i < i_nbTracks; ++i)
{
jstring name = (*env)->NewStringUTF(env, desc->psz_name);
(*env)->SetObjectArrayElement(env, array, i, name);
desc = desc->p_next;
}
libvlc_track_description_list_release(first);
return array;
}
jint Java_org_videolan_vlc_LibVLC_getAudioTrack(JNIEnv *env, jobject thiz)
{
libvlc_media_player_t *mp = getMediaPlayer(env, thiz);
if (mp)
return libvlc_audio_get_track(mp);
return -1;
}
jint Java_org_videolan_vlc_LibVLC_setAudioTrack(JNIEnv *env, jobject thiz, jint index)
{
libvlc_media_player_t *mp = getMediaPlayer(env, thiz);
if (mp)
return libvlc_audio_set_track(mp, index);
return -1;
}
jint Java_org_videolan_vlc_LibVLC_getVideoTracksCount(JNIEnv *env, jobject thiz) jint Java_org_videolan_vlc_LibVLC_getVideoTracksCount(JNIEnv *env, jobject thiz)
{ {
libvlc_media_player_t *mp = getMediaPlayer(env, thiz); libvlc_media_player_t *mp = getMediaPlayer(env, thiz);
......
...@@ -31,20 +31,42 @@ ...@@ -31,20 +31,42 @@
<TextView <TextView
android:id="@+id/player_overlay_title" android:id="@+id/player_overlay_title"
android:layout_width="0dp" android:layout_width="0dp"
android:layout_height="wrap_content" android:layout_height="fill_parent"
android:layout_weight="1" android:layout_weight="1"
android:gravity="left|center_vertical" android:gravity="left|center_vertical"
android:text="@string/title" android:text="@string/title"
android:textColor="#ffffff" android:textColor="#ffffff"
android:textSize="15dip" /> android:textSize="15dip" />
<TextView <ImageButton
android:id="@+id/player_overlay_battery" android:id="@+id/player_overlay_audio"
android:layout_width="40dp"
android:layout_height="40dp"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
android:background="@drawable/header_icon_audio" />
<LinearLayout
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:gravity="right|center_vertical" android:orientation="vertical" >
android:textColor="#ffffff"
android:textSize="15dip" /> <TextView
android:id="@+id/player_overlay_systime"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="right|center_vertical"
android:textColor="#ffffff"
android:textSize="15dip" />
<TextView
android:id="@+id/player_overlay_battery"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="right|center_vertical"
android:textColor="#ffffff"
android:textSize="15dip" />
</LinearLayout>
</LinearLayout> </LinearLayout>
<RelativeLayout <RelativeLayout
......
...@@ -346,6 +346,18 @@ public class LibVLC { ...@@ -346,6 +346,18 @@ public class LibVLC {
private native TrackInfo[] readTracksInfo(int instance, String mrl); private native TrackInfo[] readTracksInfo(int instance, String mrl);
public native int getAudioTracksCount();
public native String[] getAudioTrackDescription();
public native int getAudioTrack();
public native int setAudioTrack(int index);
public native int getVideoTracksCount();
public native int getSpuTracksCount();
/** /**
* Return true if there is a video track in the file * Return true if there is a video track in the file
*/ */
......
...@@ -30,8 +30,11 @@ import org.videolan.vlc.R; ...@@ -30,8 +30,11 @@ import org.videolan.vlc.R;
import org.videolan.vlc.Util; import org.videolan.vlc.Util;
import android.app.Activity; import android.app.Activity;
import android.app.AlertDialog;
import android.app.AlertDialog.Builder;
import android.content.BroadcastReceiver; import android.content.BroadcastReceiver;
import android.content.Context; import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent; import android.content.Intent;
import android.content.IntentFilter; import android.content.IntentFilter;
import android.content.pm.ActivityInfo; import android.content.pm.ActivityInfo;
...@@ -44,6 +47,7 @@ import android.os.Handler; ...@@ -44,6 +47,7 @@ import android.os.Handler;
import android.os.Message; import android.os.Message;
import android.os.PowerManager; import android.os.PowerManager;
import android.os.PowerManager.WakeLock; import android.os.PowerManager.WakeLock;
import android.text.format.DateFormat;
import android.util.Log; import android.util.Log;
import android.view.Display; import android.view.Display;
import android.view.MotionEvent; import android.view.MotionEvent;
...@@ -89,11 +93,13 @@ public class VideoPlayerActivity extends Activity { ...@@ -89,11 +93,13 @@ public class VideoPlayerActivity extends Activity {
private boolean mShowing; private boolean mShowing;
private SeekBar mSeekbar; private SeekBar mSeekbar;
private TextView mTitle; private TextView mTitle;
private TextView mSysTime;
private TextView mBattery; private TextView mBattery;
private TextView mTime; private TextView mTime;
private TextView mLength; private TextView mLength;
private TextView mInfo; private TextView mInfo;
private SeekBar mWheel; private SeekBar mWheel;
private ImageButton mAudio;
private ImageButton mLock; private ImageButton mLock;
private ImageButton mSize; private ImageButton mSize;
...@@ -110,6 +116,7 @@ public class VideoPlayerActivity extends Activity { ...@@ -110,6 +116,7 @@ public class VideoPlayerActivity extends Activity {
private int mAudioDisplayRange; private int mAudioDisplayRange;
private float mTouchY, mVol; private float mTouchY, mVol;
private boolean mIsAudioChanged; private boolean mIsAudioChanged;
private String[] mAudioTracks;
//Wheel //Wheel
private static final int WHEEL_DEAD_ZONE = 7; private static final int WHEEL_DEAD_ZONE = 7;
...@@ -133,6 +140,7 @@ public class VideoPlayerActivity extends Activity { ...@@ -133,6 +140,7 @@ public class VideoPlayerActivity extends Activity {
/* header */ /* header */
mTitle = (TextView) findViewById(R.id.player_overlay_title); mTitle = (TextView) findViewById(R.id.player_overlay_title);
mSysTime = (TextView) findViewById(R.id.player_overlay_systime);
mBattery = (TextView) findViewById(R.id.player_overlay_battery); mBattery = (TextView) findViewById(R.id.player_overlay_battery);
mTime = (TextView) findViewById(R.id.player_overlay_time); mTime = (TextView) findViewById(R.id.player_overlay_time);
...@@ -146,6 +154,9 @@ public class VideoPlayerActivity extends Activity { ...@@ -146,6 +154,9 @@ public class VideoPlayerActivity extends Activity {
mWheel.setProgress(mMiddle); mWheel.setProgress(mMiddle);
mWheel.setOnSeekBarChangeListener(mWheelListener); mWheel.setOnSeekBarChangeListener(mWheelListener);
mAudio = (ImageButton) findViewById(R.id.player_overlay_audio);
mAudio.setOnClickListener(mAudioListener);
mLock = (ImageButton) findViewById(R.id.player_overlay_lock); mLock = (ImageButton) findViewById(R.id.player_overlay_lock);
mLock.setOnClickListener(mLockListener); mLock.setOnClickListener(mLockListener);
...@@ -545,6 +556,26 @@ public class VideoPlayerActivity extends Activity { ...@@ -545,6 +556,26 @@ public class VideoPlayerActivity extends Activity {
}; };
private OnClickListener mAudioListener = new OnClickListener() {
public void onClick(View v) {
if (mAudioTracks == null || mAudioTracks.length <= 1)
return;
int current = mLibVLC.getAudioTrack() - 1;
Builder builder = new AlertDialog.Builder(VideoPlayerActivity.this);
builder.setSingleChoiceItems(mAudioTracks, current, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
dialog.dismiss();
mLibVLC.setAudioTrack(which + 1);
}
});
builder.show();
}
};
/** /**
* *
*/ */
...@@ -638,6 +669,13 @@ public class VideoPlayerActivity extends Activity { ...@@ -638,6 +669,13 @@ public class VideoPlayerActivity extends Activity {
mHandler.removeMessages(FADE_OUT); mHandler.removeMessages(FADE_OUT);
mHandler.sendMessageDelayed(msg, timeout); mHandler.sendMessageDelayed(msg, timeout);
} }
if (mAudioTracks == null) {
mAudioTracks = mLibVLC.getAudioTrackDescription();
if (mAudioTracks != null && mAudioTracks.length > 1)
mAudio.setVisibility(View.VISIBLE);
else
mAudio.setVisibility(View.GONE);
}
updateOverlayPausePlay(); updateOverlayPausePlay();
} }
...@@ -699,6 +737,7 @@ public class VideoPlayerActivity extends Activity { ...@@ -699,6 +737,7 @@ public class VideoPlayerActivity extends Activity {
mSeekbar.setMax(length); mSeekbar.setMax(length);
mSeekbar.setProgress(time); mSeekbar.setProgress(time);
mSysTime.setText(DateFormat.format("kk:mm", System.currentTimeMillis()));
mTime.setText(Util.millisToString(time)); mTime.setText(Util.millisToString(time));
mLength.setText(Util.millisToString(length)); mLength.setText(Util.millisToString(length));
return time; return time;
......
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