mirror of
https://github.com/sifacaii/VlcJellyfin
synced 2025-06-03 00:58:06 -04:00
添加进度报告
This commit is contained in:
parent
611ddc5dbe
commit
ba452b2962
@ -115,31 +115,41 @@ public class Utils {
|
|||||||
return (i * metrics.densityDpi) / DisplayMetrics.DENSITY_DEFAULT;
|
return (i * metrics.densityDpi) / DisplayMetrics.DENSITY_DEFAULT;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public enum ReportType{
|
||||||
|
playing,
|
||||||
|
Progress,
|
||||||
|
stop
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 报告播放开始
|
||||||
|
* @param PositionTicks
|
||||||
|
*/
|
||||||
|
public static void ReportPlaying(long PositionTicks){
|
||||||
|
String url = JellyfinUrl + "/Sessions/Playing";
|
||||||
|
String json = "{\"itemId\":\"" + playList.get(playIndex).Id + "\",\"PositionTicks\":\"" + PositionTicks * 10000 + "\"}";
|
||||||
|
okhttpSend(url,json);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 报告播放进度
|
* 报告播放进度
|
||||||
* @param baseUrl
|
|
||||||
* @param Id
|
|
||||||
* @param paused
|
* @param paused
|
||||||
* @param PositionTicks
|
* @param PositionTicks
|
||||||
* @param token
|
|
||||||
*/
|
*/
|
||||||
public static void ReportPlaybackProgress(String baseUrl, String Id, boolean paused, long PositionTicks,String token) {
|
public static void ReportPlaybackProgress(boolean paused, long PositionTicks) {
|
||||||
String json = "{\"itemId\" : \"" + Id + "\",\"canSeek\" : \"true\",\"isPaused\":\"" + paused + "\",\"isMuted\":\"false\",";
|
String json = "{\"itemId\" : \"" + playList.get(playIndex).Id + "\",\"canSeek\" : \"true\",\"isPaused\":\"" + paused + "\",\"isMuted\":\"false\",";
|
||||||
json += "\"positionTicks\": \"" + PositionTicks * 10000 + "\",\"PlayMethod\":\"DirectStream\"}";
|
json += "\"positionTicks\": \"" + PositionTicks * 10000 + "\",\"PlayMethod\":\"DirectPlay\"}";
|
||||||
String url = baseUrl + "/Sessions/Playing/Progress";
|
String url = JellyfinUrl + "/Sessions/Playing/Progress";
|
||||||
okhttpSend(url,json);
|
okhttpSend(url,json);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 播放停止
|
* 播放停止
|
||||||
* @param baseUrl
|
|
||||||
* @param Id
|
|
||||||
* @param PositionTicks
|
* @param PositionTicks
|
||||||
* @param token
|
|
||||||
*/
|
*/
|
||||||
public static void ReportPlaybackStop(String baseUrl, String Id, long PositionTicks,String token) {
|
public static void ReportPlaybackStop(long PositionTicks) {
|
||||||
String url = baseUrl + "/Sessions/Playing/Stopped";
|
String url = JellyfinUrl + "/Sessions/Playing/Stopped";
|
||||||
String json = "{\"itemId\":\"" + Id + "\",\"PositionTicks\":\"" + PositionTicks * 10000 + "\"}";
|
String json = "{\"itemId\":\"" + playList.get(playIndex).Id + "\",\"PositionTicks\":\"" + PositionTicks * 10000 + "\"}";
|
||||||
okhttpSend(url,json);
|
okhttpSend(url,json);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -165,24 +175,4 @@ public class Utils {
|
|||||||
}
|
}
|
||||||
return "";
|
return "";
|
||||||
}
|
}
|
||||||
|
|
||||||
public static int dp2px(Context context, float value) {
|
|
||||||
return (int) (TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, value, context.getResources().getDisplayMetrics()) + 0.5f);
|
|
||||||
}
|
|
||||||
|
|
||||||
public static int sp2px(Context context, float value) {
|
|
||||||
return (int) (TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_SP, value, context.getResources().getDisplayMetrics()) + 0.5f);
|
|
||||||
}
|
|
||||||
|
|
||||||
public static int pt2px(Context context, float value) {
|
|
||||||
return (int) (TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_PT, value, context.getResources().getDisplayMetrics()) + 0.5f);
|
|
||||||
}
|
|
||||||
|
|
||||||
public static int in2px(Context context, float value) {
|
|
||||||
return (int) (TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_IN, value, context.getResources().getDisplayMetrics()) + 0.5f);
|
|
||||||
}
|
|
||||||
|
|
||||||
public static int mm2px(Context context, float value) {
|
|
||||||
return (int) (TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_MM, value, context.getResources().getDisplayMetrics()) + 0.5f);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
@ -65,6 +65,10 @@ public class VlcPlayerActivity extends BaseActivity implements MediaPlayer.Event
|
|||||||
|
|
||||||
private float speedRate[] = {0.5f, 1.0f, 1.5f, 2.0f}; //倍速播放列表
|
private float speedRate[] = {0.5f, 1.0f, 1.5f, 2.0f}; //倍速播放列表
|
||||||
|
|
||||||
|
private int ReportTime = 20; // 报告进度间隔次数
|
||||||
|
private int ReportVal = 0; //累积次数
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void onCreate(Bundle savedInstanceState) {
|
protected void onCreate(Bundle savedInstanceState) {
|
||||||
super.onCreate(savedInstanceState);
|
super.onCreate(savedInstanceState);
|
||||||
@ -94,16 +98,17 @@ public class VlcPlayerActivity extends BaseActivity implements MediaPlayer.Event
|
|||||||
Hide();
|
Hide();
|
||||||
pauseFlag.setVisibility(View.GONE);
|
pauseFlag.setVisibility(View.GONE);
|
||||||
Log.d(TAG, "onEvent: 打开成功");
|
Log.d(TAG, "onEvent: 打开成功");
|
||||||
|
ReportPlayState(Utils.ReportType.playing);
|
||||||
initMenu();
|
initMenu();
|
||||||
break;
|
break;
|
||||||
case MediaPlayer.Event.Paused: //暂停
|
case MediaPlayer.Event.Paused: //暂停
|
||||||
pauseFlag.setVisibility(View.VISIBLE);
|
pauseFlag.setVisibility(View.VISIBLE);
|
||||||
break;
|
break;
|
||||||
case MediaPlayer.Event.Stopped:
|
case MediaPlayer.Event.Stopped:
|
||||||
|
ReportPlayState(Utils.ReportType.stop);
|
||||||
playNext();
|
playNext();
|
||||||
break;
|
break;
|
||||||
case MediaPlayer.Event.Opening: //媒体打开
|
case MediaPlayer.Event.Opening: //媒体打开
|
||||||
Log.d(TAG, "onEvent: 媒体打开");
|
|
||||||
break;
|
break;
|
||||||
case MediaPlayer.Event.Buffering: //媒体加载public float getBuffering() 获取加载视频流的进度0-100
|
case MediaPlayer.Event.Buffering: //媒体加载public float getBuffering() 获取加载视频流的进度0-100
|
||||||
int Buffering = (int) event.getBuffering();
|
int Buffering = (int) event.getBuffering();
|
||||||
@ -115,7 +120,6 @@ public class VlcPlayerActivity extends BaseActivity implements MediaPlayer.Event
|
|||||||
Log.d(TAG, "onEvent: 取消loading");
|
Log.d(TAG, "onEvent: 取消loading");
|
||||||
dismissLoadingDialog();
|
dismissLoadingDialog();
|
||||||
}
|
}
|
||||||
Log.d(TAG, "onEvent: 加载:" + Buffering);
|
|
||||||
break;
|
break;
|
||||||
case MediaPlayer.Event.EndReached://媒体播放结束
|
case MediaPlayer.Event.EndReached://媒体播放结束
|
||||||
Log.d(TAG, "onEvent: EndReached");
|
Log.d(TAG, "onEvent: EndReached");
|
||||||
@ -124,7 +128,11 @@ public class VlcPlayerActivity extends BaseActivity implements MediaPlayer.Event
|
|||||||
Log.d(TAG, "onEvent: EncounteredError");
|
Log.d(TAG, "onEvent: EncounteredError");
|
||||||
break;
|
break;
|
||||||
case MediaPlayer.Event.TimeChanged://视频时间变化
|
case MediaPlayer.Event.TimeChanged://视频时间变化
|
||||||
//setSeekBar(event.getTimeChanged());
|
ReportVal += 1;
|
||||||
|
if(ReportVal > ReportTime){
|
||||||
|
ReportPlayState(Utils.ReportType.Progress);
|
||||||
|
ReportVal = 0;
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
case MediaPlayer.Event.PositionChanged://视频总时长的百分比
|
case MediaPlayer.Event.PositionChanged://视频总时长的百分比
|
||||||
Log.d(TAG, "onEvent: 百分之:" + mediaPlayer.getPosition());
|
Log.d(TAG, "onEvent: 百分之:" + mediaPlayer.getPosition());
|
||||||
@ -531,4 +539,20 @@ public class VlcPlayerActivity extends BaseActivity implements MediaPlayer.Event
|
|||||||
speedMenu.show(String.valueOf(mediaPlayer.getRate()));
|
speedMenu.show(String.valueOf(mediaPlayer.getRate()));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void ReportPlayState(Utils.ReportType type){
|
||||||
|
long currplaytime = mediaPlayer.getTime();
|
||||||
|
new Thread(new Runnable() {
|
||||||
|
@Override
|
||||||
|
public void run() {
|
||||||
|
if(type == Utils.ReportType.playing){
|
||||||
|
Utils.ReportPlaying(currplaytime);
|
||||||
|
}else if(type == Utils.ReportType.stop){
|
||||||
|
Utils.ReportPlaybackStop(currplaytime);
|
||||||
|
}else if(type == Utils.ReportType.Progress){
|
||||||
|
Utils.ReportPlaybackProgress(!mediaPlayer.isPlaying(),currplaytime);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}).start();
|
||||||
|
}
|
||||||
}
|
}
|
Loading…
x
Reference in New Issue
Block a user