Skip to content

Commit

Permalink
支持弹幕 (takagen99#161)
Browse files Browse the repository at this point in the history
  • Loading branch information
cyf783 authored Sep 9, 2024
1 parent 8421fdf commit 06bfe75
Show file tree
Hide file tree
Showing 25 changed files with 1,433 additions and 6 deletions.
2 changes: 1 addition & 1 deletion .idea/compiler.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion .idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 5 additions & 0 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,11 @@ dependencies {
implementation 'io.github.inflationx:calligraphy3:3.1.1'
implementation 'com.yanzhenjie.andserver:api:2.1.12'
kapt 'com.yanzhenjie.andserver:processor:2.1.12'
implementation 'com.github.ctiao:DanmakuFlameMaster:0.9.25'
implementation('org.simpleframework:simple-xml:2.7.1') {
exclude group: 'stax', module: 'stax-api'
exclude group: 'xpp3', module: 'xpp3'
}
configurations {
configureEach {
exclude group: 'xpp3', module: 'xpp3'
Expand Down
14 changes: 14 additions & 0 deletions app/proguard-rules.pro
Original file line number Diff line number Diff line change
Expand Up @@ -304,3 +304,17 @@
-dontwarn org.joda.time.format.ISODateTimeFormat
-dontwarn org.kxml2.io.KXmlParser
-dontwarn org.xmlpull.mxp1.MXParser

# SimpleXML
-keep interface org.simpleframework.xml.core.Label { public *; }
-keep class * implements org.simpleframework.xml.core.Label { public *; }
-keep interface org.simpleframework.xml.core.Parameter { public *; }
-keep class * implements org.simpleframework.xml.core.Parameter { public *; }
-keep interface org.simpleframework.xml.core.Extractor { public *; }
-keep class * implements org.simpleframework.xml.core.Extractor { public *; }
-keepclassmembers,allowobfuscation class * { @org.simpleframework.xml.Path <fields>; }
-keepclassmembers,allowobfuscation class * { @org.simpleframework.xml.Root <fields>; }
-keepclassmembers,allowobfuscation class * { @org.simpleframework.xml.Text <fields>; }
-keepclassmembers,allowobfuscation class * { @org.simpleframework.xml.Element <fields>; }
-keepclassmembers,allowobfuscation class * { @org.simpleframework.xml.Attribute <fields>; }
-keepclassmembers,allowobfuscation class * { @org.simpleframework.xml.ElementList <fields>; }
19 changes: 18 additions & 1 deletion app/src/main/java/com/github/tvbox/osc/base/App.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
package com.github.tvbox.osc.base;

import android.os.Environment;
import android.os.Handler;
import android.os.Looper;

import androidx.core.os.HandlerCompat;
import androidx.multidex.MultiDexApplication;

import com.github.catvod.crawler.JarLoader;
Expand Down Expand Up @@ -48,11 +51,16 @@ public class App extends MultiDexApplication {
private static String dashData;
public static ViewPump viewPump = null;
private static Server server = null;
private final Handler handler;

public App() {
instance = this;
handler = HandlerCompat.createAsync(Looper.getMainLooper());
}

@Override
public void onCreate() {
super.onCreate();
instance = this;
SubtitleHelper.initSubtitleColor(this);
initParams();
// takagen99 : Initialize Locale
Expand Down Expand Up @@ -197,4 +205,13 @@ public void onException(Exception e) {
}).build();
server.startup();
}

public static void post(Runnable runnable) {
getInstance().handler.post(runnable);
}

public static void post(Runnable runnable, long delayMillis) {
getInstance().handler.removeCallbacks(runnable);
if (delayMillis >= 0) getInstance().handler.postDelayed(runnable, delayMillis);
}
}
49 changes: 49 additions & 0 deletions app/src/main/java/com/github/tvbox/osc/bean/Danmu.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
package com.github.tvbox.osc.bean;

import android.text.TextUtils;

import org.simpleframework.xml.Attribute;
import org.simpleframework.xml.ElementList;
import org.simpleframework.xml.Root;
import org.simpleframework.xml.Text;
import org.simpleframework.xml.core.Persister;

import java.util.Collections;
import java.util.List;

@Root(name = "i", strict = false)
public class Danmu {

@ElementList(entry = "d", required = false, inline = true)
private List<Data> data;

public static Danmu fromXml(String str) {
try {
return new Persister().read(Danmu.class, str);
} catch (Exception e) {
e.printStackTrace();
return new Danmu();
}
}

public List<Data> getData() {
return data == null ? Collections.emptyList() : data;
}

public static class Data {

@Attribute(name = "p", required = false)
public String param;

@Text(required = false)
public String text;

public String getParam() {
return TextUtils.isEmpty(param) ? "" : param;
}

public String getText() {
return TextUtils.isEmpty(text) ? "" : text;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ public class RefreshEvent {
public static final int TYPE_APP_REFRESH = 15;
public static final int TYPE_FILTER_CHANGE = 16;
public static final int TYPE_REFRESH_NOTIFY = 17;
public static final int TYPE_SET_DANMU_SETTINGS = 18;
public int type;
public Object obj;

Expand Down
84 changes: 83 additions & 1 deletion app/src/main/java/com/github/tvbox/osc/player/MyVideoView.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,18 @@
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;

import com.github.tvbox.osc.base.App;

import master.flame.danmaku.controller.DrawHandler;
import master.flame.danmaku.danmaku.model.BaseDanmaku;
import master.flame.danmaku.danmaku.model.DanmakuTimer;
import master.flame.danmaku.ui.widget.DanmakuView;
import xyz.doikki.videoplayer.player.AbstractPlayer;
import xyz.doikki.videoplayer.player.VideoView;

public class MyVideoView extends VideoView {
public class MyVideoView extends VideoView implements DrawHandler.Callback {
private DanmakuView danmuView;

public MyVideoView(@NonNull Context context) {
super(context, null);
}
Expand All @@ -26,4 +34,78 @@ public AbstractPlayer getMediaPlayer() {
return mMediaPlayer;
}

public int[] getVideoSize(){
return mVideoSize;
}

@Override
public void seekTo(long pos) {
super.seekTo(pos);
if (haveDanmu()) danmuView.seekTo(pos);
}

@Override
public void resume() {
super.resume();
if (haveDanmu()) danmuView.resume();
}

@Override
public void start() {
super.start();
if (haveDanmu()) danmuView.resume();
}

@Override
public void pause() {
super.pause();
if (haveDanmu()) danmuView.pause();
}

@Override
public void stopPlay() {
super.stopPlay();
if (haveDanmu()) danmuView.stop();
}

@Override
public void release() {
super.release();
if (haveDanmu()) danmuView.release();
}

private boolean haveDanmu() {
return danmuView != null && danmuView.isPrepared();
}

public void setDanmuView(DanmakuView view) {
view.setCallback(this);
danmuView = view;
}
public DanmakuView getDanmuView() {
return danmuView;
}

@Override
public void prepared() {
App.post(() -> {
if (danmuView == null) return;
if (isPlaying() && danmuView.isPrepared()) danmuView.start(getCurrentPosition());
});
}

@Override
public void updateTimer(DanmakuTimer timer) {

}

@Override
public void danmakuShown(BaseDanmaku danmaku) {

}

@Override
public void drawingFinished() {

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,7 @@ public void callback(Message msg) {
if (((BaseActivity) mActivity).supportsTouch()) {
mBack.setVisibility(VISIBLE);
}
updateDanmuBtn();
showLockView();

if (isKeyUp) {
Expand Down Expand Up @@ -208,6 +209,7 @@ public void onAnimationEnd(Animator animation) {
mBottomRoot.clearAnimation();
}
});
mDanmuSetting.setVisibility(GONE);
mBack.setVisibility(GONE);
mLockView.setVisibility(GONE);
break;
Expand Down Expand Up @@ -252,6 +254,10 @@ public void onAnimationEnd(Animator animation) {
// center BACK button
LinearLayout mBack;

LinearLayout mDanmuSetting;

private boolean hasDanmu = false;

//center LOCK button
private boolean isLock = false;
ImageView mLockView;
Expand Down Expand Up @@ -368,6 +374,7 @@ protected void initView() {

// center back button
mBack = findViewById(R.id.tvBackButton);
mDanmuSetting = findViewById(R.id.ll_danmu_setting);

// center lock button
mLockView = findViewById(R.id.tv_lock);
Expand Down Expand Up @@ -421,6 +428,7 @@ protected void initView() {
mTopRoot.setVisibility(INVISIBLE);
mBottomRoot.setVisibility(INVISIBLE);
mBack.setVisibility(INVISIBLE);
mDanmuSetting.setVisibility(INVISIBLE);

// initialize subtitle
initSubtitleInfo();
Expand Down Expand Up @@ -964,6 +972,7 @@ public void onClick(View view) {
mBack.setVisibility(GONE);
mLockView.setVisibility(GONE);
mProgressTop.setVisibility(GONE);
mDanmuSetting.setVisibility(GONE);
mHandler.removeCallbacks(mHideBottomRunnable);
if (mActivity != null) {
if (mActivity.getClass().getSimpleName().equals("DetailActivity")) {
Expand Down Expand Up @@ -992,6 +1001,10 @@ public void onClick(View view) {
}
});

mDanmuSetting.setOnClickListener(view -> {
listener.showDanmuSetting();
});

}

public void initLandscapePortraitBtnInfo() {
Expand Down Expand Up @@ -1094,6 +1107,8 @@ public interface VodControlListener {

void openVideo();

void showDanmuSetting();

}

public void setListener(VodControlListener listener) {
Expand Down Expand Up @@ -1603,4 +1618,16 @@ public boolean onBackPressed() {
}
return false;
}

public void updateDanmuBtn(){
if(hasDanmu){
mDanmuSetting.setVisibility(VISIBLE);
}else{
mDanmuSetting.setVisibility(GONE);
}
}

public void setHasDanmu(boolean hasDanmu){
this.hasDanmu = hasDanmu;
}
}
Loading

0 comments on commit 06bfe75

Please sign in to comment.