Skip to content

Commit

Permalink
✨ add vlc player impl
Browse files Browse the repository at this point in the history
  • Loading branch information
ourfor committed Dec 7, 2024
1 parent cce90a1 commit 6204a84
Show file tree
Hide file tree
Showing 16 changed files with 333 additions and 16 deletions.
4 changes: 3 additions & 1 deletion android/app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,8 @@ dependencies {
implementation(libs.jackson.annotations)
implementation(libs.jackson.databind)

implementation(libs.libvlc.all)

// http
implementation(libs.okhttp)

Expand Down Expand Up @@ -115,5 +117,5 @@ dependencies {
implementation libs.androidx.room.runtime
annotationProcessor libs.androidx.room.compiler

debugImplementation("com.reqable.android:user-certificate-trust:1.0.0")
debugImplementation(libs.user.certificate.trust)
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package top.ourfor.app.iplayx.common.type;

public enum PlayerKernelType {
MPV,
VLC,
EXO,
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
import lombok.val;
import top.ourfor.app.iplayx.bean.KVStorage;
import top.ourfor.app.iplayx.common.type.LayoutType;
import top.ourfor.app.iplayx.common.type.PlayerKernelType;
import top.ourfor.app.iplayx.common.type.VideoDecodeType;
import top.ourfor.app.iplayx.common.type.PictureQuality;
import top.ourfor.app.iplayx.page.setting.theme.ThemeColorModel;
Expand All @@ -42,6 +43,7 @@ public class AppSetting {
public PictureQuality pictureQuality;
public boolean usePictureMultiThread;
public boolean useExoPlayer;
public PlayerKernelType playerKernel;
public String mpvConfig;
public String fontFamily;
public String webHomePage;
Expand All @@ -58,11 +60,11 @@ static AppSetting getShared() {
instance.turnOffAutoUpgrade = DeviceUtil.isTV || DeviceUtil.isDebugPackage;
instance.webHomePage = "https://bing.com";
instance.pictureQuality = PictureQuality.Auto;
instance.useExoPlayer = false;
instance.playerKernel = PlayerKernelType.MPV;
instance.layoutType = LayoutType.Auto;
if (DeviceUtil.isTV) {
instance.videoDecodeType = VideoDecodeType.Hardware;
instance.useExoPlayer = true;
instance.playerKernel = PlayerKernelType.EXO;
}
}
return instance;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
package top.ourfor.app.iplayx.page.setting.video;

import androidx.annotation.NonNull;

import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;
import lombok.With;
import top.ourfor.app.iplayx.common.type.PlayerKernelType;
import top.ourfor.app.iplayx.page.setting.theme.ThemeModel;

@Builder
@With
@Data
@NoArgsConstructor
@AllArgsConstructor
public class PlayerKernelModel {

@Builder.Default
PlayerKernelType type = PlayerKernelType.MPV;
String title;

@NonNull
public String toString() {
return title != null ? title : super.toString();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
import lombok.val;
import top.ourfor.app.iplayx.R;
import top.ourfor.app.iplayx.common.annotation.ViewController;
import top.ourfor.app.iplayx.common.type.PlayerKernelType;
import top.ourfor.app.iplayx.config.AppSetting;
import top.ourfor.app.iplayx.common.type.VideoDecodeType;
import top.ourfor.app.iplayx.page.Page;
Expand Down Expand Up @@ -51,15 +52,28 @@ public void onCreate(@Nullable Bundle savedInstanceState) {
break;
}
}
var kernelOptions = List.of(
new OptionModel<>(PlayerKernelType.VLC, getContext().getString(R.string.player_vlc)),
new OptionModel<>(PlayerKernelType.MPV, getContext().getString(R.string.player_mpv)),
new OptionModel<>(PlayerKernelType.EXO, getContext().getString(R.string.player_exo))
);
var defaultPlayerKernelOption = kernelOptions.get(0);
for (val option : kernelOptions) {
if (option.value == AppSetting.shared.playerKernel) {
defaultPlayerKernelOption = option;
break;
}
}
settingModels = List.of(
SettingModel.builder()
.title(getContext().getString(R.string.use_exo_player))
.type(SettingType.SWITCH)
.value(AppSetting.shared.useExoPlayer)
.title(getContext().getString(R.string.select_player_kernel))
.type(SettingType.SELECT)
.value(defaultPlayerKernelOption)
.options(kernelOptions)
.onClick(object -> {
if (!(object instanceof Boolean)) return;
val value = (Boolean) object;
AppSetting.shared.useExoPlayer = value;
if (!(object instanceof OptionModel<?>)) return;
val value = (OptionModel<PlayerKernelType>) object;
AppSetting.shared.playerKernel = value.value;
AppSetting.shared.save();
})
.build(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

import top.ourfor.app.iplayx.view.video.PlayerEventListener;
import top.ourfor.app.iplayx.view.video.PlayerSourceModel;
import top.ourfor.lib.mpv.TrackItem;

public interface Player {
default void setDelegate(PlayerEventListener delegate) {}
Expand All @@ -28,8 +29,8 @@ default void jumpBackward(int seconds) {}
default void jumpForward(int seconds) {}
default void stop() {}
default void resize(String newSize) {}
default List audios() { return null; }
default List subtitles() { return null; }
default List<TrackItem> audios() { return null; }
default List<TrackItem> subtitles() { return null; }
default void loadSubtitle(List<PlayerSourceModel> subtitles) {}
default String currentSubtitleId() { return "no"; }
default String currentAudioId() { return "no"; }
Expand All @@ -39,15 +40,15 @@ default void setSubtitleDelay(double delay) {}
default void setSubtitlePosition(double position) {}
default void destroy() {}

void useSubtitle(String id);
void useAudio(String id);
default void useSubtitle(String id) {};
default void useAudio(String id) {};
default void useVideo(String id) {};

default void applyOption(Map<String, String> option) {};

default void speedUp(float speed) {}
default void speedDown(float speed) {}

default void useVideo(String id) {};

default void setLastWatchPosition(long lastWatchPosition) {};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,20 @@ public PlayerContentView(Context context) {
}

public void initialize(String configDir, String cacheDir, String fontDir) {
viewModel = AppSetting.shared.useExoPlayer ? new ExoPlayerViewModel(this) : new MPVPlayerViewModel(configDir, cacheDir, fontDir);
switch (AppSetting.shared.playerKernel) {
case VLC:
viewModel = new VLCPlayerViewModel(this);
break;
case MPV:
viewModel = new MPVPlayerViewModel(configDir, cacheDir, fontDir);
break;
case EXO:
viewModel = new ExoPlayerViewModel(this);
break;
default:
log.info("Using default player: MPV");
viewModel = new MPVPlayerViewModel(configDir, cacheDir, fontDir);
}
setZOrderMediaOverlay(false);
// we need to call write-watch-later manually
getHolder().addCallback(this);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -414,7 +414,7 @@ public void onPipEnter() {

@Override
public void onAdvanceConfig() {
var dialog = new Dialog(getContext());
var dialog = new Dialog(getContext(), R.style.PlayerAdvanceConfigDialog);
var contentView = new PlayerAdvanceConfigView(getContext());
contentView.player = this.controlView.player;
dialog.setContentView(contentView);
Expand Down
Loading

0 comments on commit 6204a84

Please sign in to comment.