Skip to content

Commit

Permalink
Merge pull request #325 from ourfor/develop
Browse files Browse the repository at this point in the history
✨ add player advance config panel
  • Loading branch information
ourfor authored Dec 6, 2024
2 parents 18c7ad4 + 08a1350 commit dc262c8
Show file tree
Hide file tree
Showing 13 changed files with 229 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@ default void loadSubtitle(List<PlayerSourceModel> subtitles) {}
default String currentAudioId() { return "no"; }
default void setSubtitleFontName(String subtitleFontName) {}
default void setSubtitleFontDirectory(String directory) {}
default void setSubtitleDelay(double delay) {}
default void setSubtitlePosition(double position) {}
default void destroy() {}

void useSubtitle(String id);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -337,6 +337,18 @@ public void seekRelative(int seconds) {
mpv.command("seek", String.valueOf(seconds), "relative+exact");
}

@Override
public void setSubtitleDelay(double delay) {
if (mpv == null) return;
mpv.setOptionString("sub-delay", String.valueOf(delay));
}

@Override
public void setSubtitlePosition(double position) {
if (mpv == null) return;
mpv.setOptionString("sub-pos", String.valueOf(position));
}

@Override
public void destroy() {
if (mpv == null) return;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
package top.ourfor.app.iplayx.view.video;

import android.content.Context;
import android.text.Editable;
import android.text.TextWatcher;
import android.view.LayoutInflater;

import androidx.annotation.NonNull;
import androidx.constraintlayout.widget.ConstraintLayout;

import top.ourfor.app.iplayx.databinding.PlayerAdvanceConfigBinding;
import top.ourfor.app.iplayx.view.player.Player;

public class PlayerAdvanceConfigView extends ConstraintLayout {
PlayerAdvanceConfigBinding binding;
Player player;

public PlayerAdvanceConfigView(@NonNull Context context) {
super(context);
binding = PlayerAdvanceConfigBinding.inflate(LayoutInflater.from(context), this, true);
setup();
bind();
}

void setup() {

}

void bind() {
binding.subDelay.addTextChangedListener(new TextWatcher() {
@Override
public void beforeTextChanged(CharSequence charSequence, int i, int i1, int i2) {

}

@Override
public void onTextChanged(CharSequence charSequence, int i, int i1, int i2) {

}

@Override
public void afterTextChanged(Editable editable) {
if (player != null) {
double delay = Double.parseDouble(editable.toString());
player.setSubtitleDelay(delay);
}
}
});

binding.subPos.addTextChangedListener(new TextWatcher() {
@Override
public void beforeTextChanged(CharSequence charSequence, int i, int i1, int i2) {

}

@Override
public void onTextChanged(CharSequence charSequence, int i, int i1, int i2) {

}

@Override
public void afterTextChanged(Editable editable) {
if (player != null) {
double position = Double.parseDouble(editable.toString());
player.setSubtitlePosition(position);
}
}
});
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ public class PlayerControlView extends ConstraintLayout implements PlayerEventLi
public PlayerControlItemView orientationButton;
public PlayerControlItemView speedButton;
public PlayerControlItemView commentButton;
public PlayerControlItemView advanceConfigButton;
public TextView timeLabel;
public TextView titleLabel;
public PlayerSlider progressBar;
Expand Down Expand Up @@ -133,6 +134,7 @@ private void setupUI() {
orientationButton = binding.orientation;
speedButton = binding.speed;
commentButton = binding.comment;
advanceConfigButton = binding.advanceConfig;
updatePlayerSlider();
}

Expand Down Expand Up @@ -184,6 +186,7 @@ public void onStopTrackingTouch(SeekBar seekBar) {
});
popup.show();
});
binding.advanceConfig.setOnClickListener(v -> delegate.onAdvanceConfig());
binding.pipEnter.setOnClickListener(v -> delegate.onPipEnter());
binding.playlist.setOnClickListener(v -> delegate.onTapPlaylist());
binding.comment.setOnClickListener(v -> delegate.onTapComment());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,5 @@ default void onTapPlaylist() {}
default void onTapComment() {}

default void onOrientationChange() {};
default void onAdvanceConfig() {}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,19 @@

import android.animation.ObjectAnimator;
import android.app.Activity;
import android.app.Dialog;
import android.content.Context;
import android.content.pm.ActivityInfo;
import android.content.res.AssetManager;
import android.graphics.Color;
import android.media.AudioManager;
import android.os.Build;
import android.util.Size;
import android.view.KeyEvent;
import android.view.ViewGroup;
import android.view.Window;
import android.view.WindowManager;
import android.widget.Button;
import android.widget.ImageView;

import androidx.annotation.NonNull;
Expand Down Expand Up @@ -212,7 +215,8 @@ void setupUI(Context context, String url) throws IOException {
controlView.pipButton,
controlView.playlistButton,
controlView.orientationButton,
controlView.speedButton
controlView.speedButton,
controlView.advanceConfigButton
);
eventView.delegate = this;
eventView.trackSelectDelegate = this;
Expand Down Expand Up @@ -408,6 +412,24 @@ public void onPipEnter() {
XGET(Activity.class).enterPictureInPictureMode();
}

@Override
public void onAdvanceConfig() {
var dialog = new Dialog(getContext());
var contentView = new PlayerAdvanceConfigView(getContext());
contentView.player = this.controlView.player;
dialog.setContentView(contentView);
Window window = dialog.getWindow();
if (window != null) {
Size size = DeviceUtil.screenSize(getContext());
WindowManager.LayoutParams dialogLayoutParams = new WindowManager.LayoutParams();
dialogLayoutParams.copyFrom(window.getAttributes());
dialogLayoutParams.width = (int) (size.getWidth() * 0.5);
dialogLayoutParams.height = (int) (size.getHeight() * 0.8);
window.setAttributes(dialogLayoutParams);
}
dialog.show();
}

@Override
public void onSelectSubtitle() {
var player = contentView.viewModel;
Expand Down
90 changes: 90 additions & 0 deletions android/app/src/main/res/layout/player_advance_config.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
<?xml version="1.0" encoding="utf-8"?>
<top.ourfor.app.iplayx.view.LifecycleHolder
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
xmlns:app="http://schemas.android.com/apk/res-auto">
<com.google.android.flexbox.FlexboxLayout
app:flexDirection="column"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<com.google.android.flexbox.FlexboxLayout
app:alignItems="center"
app:justifyContent="center"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<top.ourfor.app.iplayx.view.infra.TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/sub_pos_label"
android:text="@string/subtitle_position"
android:textSize="18sp"
android:maxLines="1"
android:ellipsize="end"
android:textColor="@color/onBackground"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintLeft_toLeftOf="parent"
android:layout_marginTop="15dp"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
android:layout_marginBottom="15dp"
app:layout_flexGrow="1"
/>
<top.ourfor.app.iplayx.view.infra.EditText
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:inputType="number"
android:id="@+id/sub_pos"
app:layout_minWidth="50dp"
android:layout_marginEnd="10dp"
/>
</com.google.android.flexbox.FlexboxLayout>
<com.google.android.flexbox.FlexboxLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<com.google.android.flexbox.FlexboxLayout
app:alignItems="center"
app:justifyContent="center"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<top.ourfor.app.iplayx.view.infra.TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/name_label"
android:text="@string/subtitle_delay"
android:textSize="18sp"
android:maxLines="1"
android:ellipsize="end"
android:textColor="@color/onBackground"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintLeft_toLeftOf="parent"
android:layout_marginTop="15dp"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
android:layout_marginBottom="15dp"
app:layout_flexGrow="1"
/>
<top.ourfor.app.iplayx.view.infra.EditText
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:inputType="number"
android:id="@+id/sub_delay"
app:layout_minWidth="50dp"
android:layout_marginEnd="10dp"
/>
</com.google.android.flexbox.FlexboxLayout>
</com.google.android.flexbox.FlexboxLayout>
<com.google.android.flexbox.FlexboxLayout
app:alignItems="center"
app:justifyContent="center"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<top.ourfor.app.iplayx.view.infra.TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/warning_label"
android:text="@string/advance_config_warning"
/>
</com.google.android.flexbox.FlexboxLayout>
</com.google.android.flexbox.FlexboxLayout>
</top.ourfor.app.iplayx.view.LifecycleHolder>
13 changes: 13 additions & 0 deletions android/app/src/main/res/layout/player_control.xml
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,19 @@
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintStart_toStartOf="parent" />

<top.ourfor.app.iplayx.view.video.PlayerControlItemView
android:layout_width="48dp"
android:layout_height="48dp"
android:id="@+id/advance_config"
app:size="48dp"
app:cornerRadius="24dp"
android:layout_margin="5dp"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toStartOf="@id/pip_enter"
app:src="@drawable/ic_fluent_settings_24_filled"
/>

<top.ourfor.app.iplayx.view.video.PlayerControlItemView
android:layout_width="48dp"
android:layout_height="48dp"
Expand Down
3 changes: 3 additions & 0 deletions android/app/src/main/res/values-night/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -130,4 +130,7 @@
<string name="video_source">视频源</string>
<string name="audio_source">音频源</string>
<string name="subtitle_source">字幕源</string>
<string name="subtitle_delay">调整字幕延时</string>
<string name="subtitle_position">字幕显示位置偏移</string>
<string name="advance_config_warning">对于部分播放器实现,某些配置可能无效</string>
</resources>
3 changes: 3 additions & 0 deletions android/app/src/main/res/values-television-night/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -85,4 +85,7 @@
<string name="video_source">视频源</string>
<string name="audio_source">音频源</string>
<string name="subtitle_source">字幕源</string>
<string name="subtitle_delay">调整字幕延时</string>
<string name="subtitle_position">字幕显示位置偏移</string>
<string name="advance_config_warning">对于部分播放器实现,某些配置可能无效</string>
</resources>
3 changes: 3 additions & 0 deletions android/app/src/main/res/values-television/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -85,4 +85,7 @@
<string name="video_source">视频源</string>
<string name="audio_source">音频源</string>
<string name="subtitle_source">字幕源</string>
<string name="subtitle_delay">调整字幕延时</string>
<string name="subtitle_position">字幕显示位置偏移</string>
<string name="advance_config_warning">对于部分播放器实现,某些配置可能无效</string>
</resources>
3 changes: 3 additions & 0 deletions android/app/src/main/res/values-zh/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -140,4 +140,7 @@
<string name="video_source">视频源</string>
<string name="audio_source">音频源</string>
<string name="subtitle_source">字幕源</string>
<string name="subtitle_delay">调整字幕延时</string>
<string name="subtitle_position">字幕显示位置偏移</string>
<string name="advance_config_warning">对于部分播放器实现,某些配置可能无效</string>
</resources>
3 changes: 3 additions & 0 deletions android/app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -140,4 +140,7 @@
<string name="video_source">视频源</string>
<string name="audio_source">音频源</string>
<string name="subtitle_source">字幕源</string>
<string name="subtitle_delay">调整字幕延时</string>
<string name="subtitle_position">字幕显示位置偏移</string>
<string name="advance_config_warning">对于部分播放器实现,某些配置可能无效</string>
</resources>

0 comments on commit dc262c8

Please sign in to comment.