From a86f9d39131bc1a1d705d7ad1e3e67791b5ed20a Mon Sep 17 00:00:00 2001 From: subhadipThinkpad Date: Mon, 24 Dec 2018 10:00:32 +0530 Subject: [PATCH] Playback speed feature implemented --- .../peertube/activity/VideoPlayActivity.java | 42 +++++++++++++++++ .../peertube/service/VideoPlayerService.java | 14 +++++- .../main/res/layout/activity_video_play.xml | 45 +++++++++++++++++++ 3 files changed, 99 insertions(+), 2 deletions(-) diff --git a/app/src/main/java/net/schueller/peertube/activity/VideoPlayActivity.java b/app/src/main/java/net/schueller/peertube/activity/VideoPlayActivity.java index b1cef54..15290d0 100644 --- a/app/src/main/java/net/schueller/peertube/activity/VideoPlayActivity.java +++ b/app/src/main/java/net/schueller/peertube/activity/VideoPlayActivity.java @@ -20,6 +20,7 @@ import android.view.Surface; import android.view.View; import android.view.ViewGroup; import android.view.WindowManager; +import android.widget.Button; import android.widget.ImageButton; import android.widget.ImageView; import android.widget.ProgressBar; @@ -230,6 +231,12 @@ public class VideoPlayActivity extends AppCompatActivity implements VideoRendere ImageView avatarView = findViewById(R.id.avatar); ImageButton moreButton = findViewById(R.id.moreButton); + //Playback speed buttons + Button speed05 = findViewById(R.id.speed05); + Button speed10 = findViewById(R.id.speed10); + Button speed15 = findViewById(R.id.speed15); + Button speed20 = findViewById(R.id.speed20); + Video video = response.body(); mService.setCurrentVideo(video); @@ -277,6 +284,41 @@ public class VideoPlayActivity extends AppCompatActivity implements VideoRendere mService.setCurrentStreamUrl(video.getFiles().get(0).getFileUrl()); + //Playback speed controls + speed05.setOnClickListener(view -> { + mService.setPlayBackSpeed(0.5f); + speed05.setTextColor(getResources().getColor(R.color.colorPrimary)); + + speed10.setTextColor(getResources().getColor(R.color.black)); + speed15.setTextColor(getResources().getColor(R.color.black)); + speed20.setTextColor(getResources().getColor(R.color.black)); + + }); + speed10.setOnClickListener(view -> { + mService.setPlayBackSpeed(1.0f); + speed10.setTextColor(getResources().getColor(R.color.colorPrimary)); + + speed05.setTextColor(getResources().getColor(R.color.black)); + speed15.setTextColor(getResources().getColor(R.color.black)); + speed20.setTextColor(getResources().getColor(R.color.black)); + }); + speed15.setOnClickListener(view -> { + mService.setPlayBackSpeed(1.5f); + speed15.setTextColor(getResources().getColor(R.color.colorPrimary)); + + speed05.setTextColor(getResources().getColor(R.color.black)); + speed10.setTextColor(getResources().getColor(R.color.black)); + speed20.setTextColor(getResources().getColor(R.color.black)); + }); + speed20.setOnClickListener(view -> { + mService.setPlayBackSpeed(2.0f); + speed20.setTextColor(getResources().getColor(R.color.colorPrimary)); + + speed05.setTextColor(getResources().getColor(R.color.black)); + speed10.setTextColor(getResources().getColor(R.color.black)); + speed15.setTextColor(getResources().getColor(R.color.black)); + }); + SharedPreferences sharedPref = PreferenceManager.getDefaultSharedPreferences(getApplicationContext()); if (sharedPref.getBoolean("pref_torrent_player", false)) { diff --git a/app/src/main/java/net/schueller/peertube/service/VideoPlayerService.java b/app/src/main/java/net/schueller/peertube/service/VideoPlayerService.java index 2f42dd1..64841bd 100644 --- a/app/src/main/java/net/schueller/peertube/service/VideoPlayerService.java +++ b/app/src/main/java/net/schueller/peertube/service/VideoPlayerService.java @@ -16,6 +16,7 @@ import android.support.annotation.Nullable; import android.util.Log; import com.google.android.exoplayer2.ExoPlayerFactory; +import com.google.android.exoplayer2.PlaybackParameters; import com.google.android.exoplayer2.Player; import com.google.android.exoplayer2.SimpleExoPlayer; import com.google.android.exoplayer2.source.ExtractorMediaSource; @@ -123,8 +124,14 @@ public class VideoPlayerService extends Service { currentStreamUrl = streamUrl; } - public void playVideo() - { + //Playback speed control + public void setPlayBackSpeed(float speed) { + + Log.v("VideoPlayerService", "setPlayBackSpeed..."); + player.setPlaybackParameters(new PlaybackParameters(speed)); + } + + public void playVideo() { Context context = this; Log.v("VideoPlayerService", "playVideo..."); @@ -143,6 +150,9 @@ public class VideoPlayerService extends Service { // Auto play player.setPlayWhenReady(true); + //reset playback speed + this.setPlayBackSpeed(1.0f); + playerNotificationManager = PlayerNotificationManager.createWithNotificationChannel( context, PLAYBACK_CHANNEL_ID, R.string.playback_channel_name, PLAYBACK_NOTIFICATION_ID, diff --git a/app/src/main/res/layout/activity_video_play.xml b/app/src/main/res/layout/activity_video_play.xml index abafd04..cf26496 100644 --- a/app/src/main/res/layout/activity_video_play.xml +++ b/app/src/main/res/layout/activity_video_play.xml @@ -108,6 +108,51 @@ android:layout_marginEnd="12dp" android:textAppearance="@style/Base.TextAppearance.AppCompat.Body1" /> + + +