Commit 41cce1ca authored by Edward Wang's avatar Edward Wang

Add playback speed feature

Close #7064
Close #7224
parent 2496206d
......@@ -546,6 +546,20 @@ void Java_org_videolan_vlc_LibVLC_readMedia(JNIEnv *env, jobject thiz,
libvlc_media_player_play(mp);
}
jfloat Java_org_videolan_vlc_LibVLC_getRate(JNIEnv *env, jobject thiz) {
libvlc_media_player_t* mp = getMediaPlayer(env, thiz);
if(mp)
return libvlc_media_player_get_rate(mp);
else
return 1.00;
}
void Java_org_videolan_vlc_LibVLC_setRate(JNIEnv *env, jobject thiz, jfloat rate) {
libvlc_media_player_t* mp = getMediaPlayer(env, thiz);
if(mp)
libvlc_media_player_set_rate(mp, rate);
}
jboolean Java_org_videolan_vlc_LibVLC_hasVideoTrack(JNIEnv *env, jobject thiz,
jint i_instance, jstring fileLocation)
{
......
......@@ -124,7 +124,7 @@
android:textSize="18dip" />
</LinearLayout>
<FrameLayout
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:orientation="vertical" >
......@@ -133,8 +133,8 @@
android:id="@+id/shuffle"
android:layout_width="40dip"
android:layout_height="40dip"
android:layout_gravity="top"
android:layout_marginTop="20dip"
android:layout_gravity="center_horizontal"
android:layout_marginTop="10dip"
android:background="#00000000"
android:onClick="onShuffleClick"
android:scaleType="fitXY"
......@@ -144,13 +144,25 @@
android:id="@+id/repeat"
android:layout_width="40dip"
android:layout_height="40dip"
android:layout_gravity="bottom"
android:layout_marginBottom="20dip"
android:layout_gravity="center_horizontal"
android:layout_marginTop="10dip"
android:background="#00000000"
android:onClick="onRepeatClick"
android:scaleType="fitXY"
android:src="@drawable/ic_repeat" />
</FrameLayout>
<TextView
android:id="@+id/current_speed"
android:layout_width="60dip"
android:layout_height="40dip"
android:layout_marginTop="10dip"
android:layout_marginBottom="10dip"
android:clickable="true"
android:onClick="onSpeedLabelClick"
android:text="1.00x"
android:textSize="24dp" />
</LinearLayout>
</LinearLayout>
<LinearLayout
......
......@@ -53,6 +53,18 @@
android:layout_marginTop="10dip"
android:id="@+id/repeat"
android:onClick="onRepeatClick" />
<TextView
android:id="@+id/current_speed"
android:text="1.00x"
android:layout_height="60dip"
android:layout_width="60dip"
android:layout_marginTop="10dip"
android:textSize="24dp"
android:gravity="center"
android:clickable="true"
android:onClick="onSpeedLabelClick" />
</LinearLayout>
</LinearLayout>
<FrameLayout
......
......@@ -51,8 +51,20 @@
android:padding="5dip"
android:layout_height="50dip"
android:layout_width="50dip"
android:layout_marginTop="-5dip"
android:layout_marginBottom="-5dip"
android:id="@+id/repeat"
android:onClick="onRepeatClick" />
<TextView
android:id="@+id/current_speed"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:clickable="true"
android:onClick="onSpeedLabelClick"
android:text="1.00x"
android:textSize="20dp" />
</LinearLayout>
</LinearLayout>
<LinearLayout
......
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:padding="10dp">
<SeekBar
android:id="@+id/speed_seek_bar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:max="200" />
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/relative_layout">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:text="0.25" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:text="1.00" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:text="4.00" />
</RelativeLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center_horizontal"
android:paddingTop="10dp">
<TextView
android:id="@+id/current_speed"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="24sp"
android:text="1.33x" />
<Button
android:id="@+id/reset"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="1x" />
</LinearLayout>
</LinearLayout>
\ No newline at end of file
......@@ -92,6 +92,8 @@
<string name="open_mrl_dialog_msg">Enter network MRL: e.g. http://, mms:// or rtsp://</string>
<string name="media_library">Media library</string>
<string name="error_not_compatible">Sorry, but your device is currently not supported by this version of VLC for Android™.\n\nThe error message is (please mention this when debugging):\n</string>
<string name="playback_speed">Playback speed</string>
<string name="time_0" translatable="false">0:00</string>
<!-- About -->
<string name="app_name_full">VLC for Android™</string>
......
......@@ -272,6 +272,18 @@ public class LibVLC {
return getLengthFromLocation(mLibVlcInstance, mrl);
}
/**
* Sets the speed of playback (1 being normal speed, 2 being twice as fast)
*
* @param rate
*/
public native void setRate(float rate);
/**
* Get the current playback speed
*/
public native float getRate();
/**
* Change the verbosity of libvlc
* @param verbose: true for increased verbosity
......
/*****************************************************************************
* SpeedSelectorDialog.java
*****************************************************************************
* Copyright © 2012 VLC authors and VideoLAN
* Copyright © 2012 Edward Wang
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
*****************************************************************************/
package org.videolan.vlc.gui;
import org.videolan.vlc.LibVLC;
import org.videolan.vlc.R;
import org.videolan.vlc.VLCApplication;
import android.app.Dialog;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.Button;
import android.widget.SeekBar;
import android.widget.TextView;
public class SpeedSelectorDialog extends Dialog {
public SpeedSelectorDialog(Context context) {
super(context);
setTitle(VLCApplication.getAppContext().getString(R.string.playback_speed));
LayoutInflater inflator = LayoutInflater.from(context);
View view = inflator.inflate(R.layout.speed_selector, null);
setContentView(view);
final SeekBar seekbar = (SeekBar)findViewById(R.id.speed_seek_bar);
final TextView speedLabel = (TextView)findViewById(R.id.current_speed);
Button resetButton = (Button)findViewById(R.id.reset);
speedLabel.setText(String.format("%.2fx", LibVLC.getExistingInstance().getRate()));
seekbar.setProgress( (int)( ((Math.log(LibVLC.getExistingInstance().getRate()) / Math.log(4)) + 1) * 100) );
seekbar.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() {
@Override
public void onProgressChanged(SeekBar seekBar, int progress,
boolean fromUser) {
float rate = (float) Math.pow((double)4, ((double)progress/(double)100) - (double)1);
speedLabel.setText(String.format("%.2fx", rate));
LibVLC.getExistingInstance().setRate(rate);
}
@Override
public void onStartTrackingTouch(SeekBar seekBar) { }
@Override
public void onStopTrackingTouch(SeekBar seekBar) { }
});
resetButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
seekbar.setProgress(100);
LibVLC.getExistingInstance().setRate((float)1);
}
});
}
}
......@@ -22,10 +22,12 @@ package org.videolan.vlc.gui.audio;
import org.videolan.vlc.AudioService;
import org.videolan.vlc.AudioServiceController;
import org.videolan.vlc.LibVLC;
import org.videolan.vlc.R;
import org.videolan.vlc.RepeatType;
import org.videolan.vlc.Util;
import org.videolan.vlc.gui.MainActivity;
import org.videolan.vlc.gui.SpeedSelectorDialog;
import org.videolan.vlc.interfaces.IAudioPlayer;
import android.app.Activity;
......@@ -51,6 +53,7 @@ public class AudioPlayerActivity extends Activity implements IAudioPlayer {
private TextView mAlbum;
private TextView mTime;
private TextView mLength;
private TextView mSpeed;
private ImageButton mPlayPause;
private ImageButton mNext;
private ImageButton mPrevious;
......@@ -81,6 +84,7 @@ public class AudioPlayerActivity extends Activity implements IAudioPlayer {
mAlbum = (TextView) findViewById(R.id.album);
mTime = (TextView) findViewById(R.id.time);
mLength = (TextView) findViewById(R.id.length);
mSpeed = (TextView) findViewById(R.id.current_speed);
mPlayPause = (ImageButton) findViewById(R.id.play_pause);
mNext = (ImageButton) findViewById(R.id.next);
mPrevious = (ImageButton) findViewById(R.id.previous);
......@@ -180,6 +184,7 @@ public class AudioPlayerActivity extends Activity implements IAudioPlayer {
mPrevious.setVisibility(ImageButton.VISIBLE);
else
mPrevious.setVisibility(ImageButton.INVISIBLE);
mSpeed.setText(String.format("%.2fx", LibVLC.getExistingInstance().getRate()));
mTimeline.setOnSeekBarChangeListener(mTimelineListner);
}
......@@ -271,4 +276,9 @@ public class AudioPlayerActivity extends Activity implements IAudioPlayer {
}
return super.onKeyDown(keyCode, event);
}
public void onSpeedLabelClick(View view) {
new SpeedSelectorDialog(this).show();
update();
}
}
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