mirror of
https://github.com/sifacaii/VlcJellyfin
synced 2025-06-03 00:58:06 -04:00
精简播放界面
This commit is contained in:
parent
43da3d5a88
commit
34237746e9
@ -12,11 +12,11 @@ import android.view.KeyEvent;
|
||||
import android.view.Menu;
|
||||
import android.view.MenuItem;
|
||||
import android.view.View;
|
||||
import android.widget.FrameLayout;
|
||||
import android.widget.ImageView;
|
||||
import android.widget.Toast;
|
||||
|
||||
import androidx.annotation.Nullable;
|
||||
|
||||
import me.jessyan.autosize.internal.CustomAdapt;
|
||||
|
||||
public class BaseActivity extends AppCompatActivity implements CustomAdapt {
|
||||
|
@ -5,10 +5,15 @@ import static android.net.sip.SipErrorCode.TIME_OUT;
|
||||
import android.annotation.SuppressLint;
|
||||
import android.app.Activity;
|
||||
import android.content.Context;
|
||||
import android.os.Bundle;
|
||||
import android.os.Handler;
|
||||
import android.os.Message;
|
||||
import android.util.DisplayMetrics;
|
||||
import android.util.Log;
|
||||
import android.util.TypedValue;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
|
||||
import com.google.gson.Gson;
|
||||
import com.google.gson.JsonElement;
|
||||
import com.google.gson.JsonObject;
|
||||
@ -29,6 +34,7 @@ import javax.net.ssl.SSLSocketFactory;
|
||||
import javax.net.ssl.TrustManager;
|
||||
import javax.net.ssl.X509TrustManager;
|
||||
|
||||
import okhttp3.Callback;
|
||||
import okhttp3.Headers;
|
||||
import okhttp3.MediaType;
|
||||
import okhttp3.OkHttpClient;
|
||||
@ -45,7 +51,6 @@ public class Utils {
|
||||
public static int playIndex = 0; //当前播放
|
||||
public static ArrayList<Video> playList = new ArrayList<>(); //播放列表
|
||||
|
||||
|
||||
/**
|
||||
* GET请求
|
||||
*
|
||||
@ -158,39 +163,29 @@ public class Utils {
|
||||
}
|
||||
|
||||
/**
|
||||
* 报告播放开始
|
||||
*
|
||||
* 报告播放状态
|
||||
* @param type
|
||||
* @param Id
|
||||
* @param PositionTicks
|
||||
*/
|
||||
public static void ReportPlaying(String Id, long PositionTicks) {
|
||||
String url = config.getJellyfinUrl() + "/Sessions/Playing";
|
||||
String json = "{\"itemId\":\"" + Id + "\",\"PositionTicks\":\"" + PositionTicks * 10000 + "\"}";
|
||||
String rsp = okhttpSend(url, json);
|
||||
//Log.d("VLC播放器", "ReportPlaying: " + Id + " : " + rsp);
|
||||
public static void ReportPlayState(ReportType type,String Id,long PositionTicks){
|
||||
String url = config.getJellyfinUrl();
|
||||
if(type == ReportType.playing){
|
||||
url += "/Sessions/Playing";
|
||||
}else if(type == ReportType.Progress){
|
||||
url += "/Sessions/Playing/Progress";
|
||||
}else if(type == ReportType.stop){
|
||||
url += "/Sessions/Playing/Stopped";
|
||||
}
|
||||
|
||||
/**
|
||||
* 报告播放进度
|
||||
*
|
||||
* @param PositionTicks
|
||||
*/
|
||||
public static void ReportPlaybackProgress(String Id, long PositionTicks) {
|
||||
String json = "{\"itemId\" : \"" + Id + "\",\"positionTicks\": \"" + PositionTicks * 10000 + "\"}";
|
||||
String url = config.getJellyfinUrl() + "/Sessions/Playing/Progress";
|
||||
String rsp = okhttpSend(url, json);
|
||||
//Log.d("VLC播放器", "ReportPlaybackProgress: 返回:" + Id + ":" + rsp);
|
||||
}
|
||||
|
||||
/**
|
||||
* 播放停止
|
||||
*
|
||||
* @param PositionTicks
|
||||
*/
|
||||
public static void ReportPlaybackStop(String Id, long PositionTicks) {
|
||||
String url = config.getJellyfinUrl() + "/Sessions/Playing/Stopped";
|
||||
String json = "{\"itemId\":\"" + Id + "\",\"PositionTicks\":\"" + PositionTicks * 10000 + "\"}";
|
||||
String rsp = okhttpSend(url, json);
|
||||
//Log.d("VLC播放器", "ReportPlaybackStop: " + Id + " : " + rsp);
|
||||
String finalUrl = url;
|
||||
new Thread(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
String rsptxt = okhttpSend(finalUrl,json);
|
||||
Log.d("Report", "run: " + rsptxt);
|
||||
}
|
||||
}).start();
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -3,6 +3,9 @@ package org.sifacai.vlcjellyfin;
|
||||
import android.app.Activity;
|
||||
import android.net.Uri;
|
||||
import android.os.Bundle;
|
||||
import android.os.Handler;
|
||||
import android.os.Looper;
|
||||
import android.os.Message;
|
||||
import android.util.Log;
|
||||
import android.view.KeyEvent;
|
||||
import android.view.View;
|
||||
@ -47,8 +50,6 @@ public class VlcPlayerActivity extends BaseActivity implements MediaPlayer.Event
|
||||
private TextView countTime;
|
||||
private TextView speedBtn;
|
||||
private TextView scaleBtn;
|
||||
private ImageView preBtn;
|
||||
private ImageView nextBtn;
|
||||
private ImageView playPauseBtn;
|
||||
private ImageView stopBtn;
|
||||
private ImageView subTracksBtn;
|
||||
@ -56,9 +57,7 @@ public class VlcPlayerActivity extends BaseActivity implements MediaPlayer.Event
|
||||
private ImageView playListBtn;
|
||||
private ImageView pauseFlag;
|
||||
private SeekBar currPostion;
|
||||
|
||||
private Timer progressTime = null; //控制器进度条更新定时
|
||||
private Timer reportProcessTime = null; // 报告进度定时器
|
||||
private ProgressBar loading;
|
||||
|
||||
private PopMenu playListMenu = null; //播放列表
|
||||
private PopMenu subTrackMenu = null; //字幕菜单
|
||||
@ -68,7 +67,9 @@ public class VlcPlayerActivity extends BaseActivity implements MediaPlayer.Event
|
||||
|
||||
private float speedRate[] = {0.5f, 1.0f, 1.5f, 2.0f}; //倍速播放列表
|
||||
|
||||
private long currPlaybackTimeTrack = 0; //当前播放进度
|
||||
private int updateTimeCount = 0;
|
||||
private int ReportCount = 30;
|
||||
private Video currItem; //当前播放项目
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
@ -101,7 +102,7 @@ public class VlcPlayerActivity extends BaseActivity implements MediaPlayer.Event
|
||||
Hide();
|
||||
pauseFlag.setVisibility(View.GONE);
|
||||
Log.d(TAG, "onEvent: Playing");
|
||||
ReportPlayState(Utils.ReportType.playing, Utils.playList.get(Utils.playIndex).Id);
|
||||
ReportPlayState(Utils.ReportType.playing);
|
||||
initMenu();
|
||||
break;
|
||||
case MediaPlayer.Event.Paused: //暂停
|
||||
@ -109,7 +110,7 @@ public class VlcPlayerActivity extends BaseActivity implements MediaPlayer.Event
|
||||
break;
|
||||
case MediaPlayer.Event.Stopped:
|
||||
Log.d(TAG, "onEvent: Stopped");
|
||||
ReportPlayState(Utils.ReportType.stop, Utils.playList.get(Utils.playIndex).Id);
|
||||
ReportPlayState(Utils.ReportType.stop);
|
||||
playNext();
|
||||
break;
|
||||
case MediaPlayer.Event.Opening: //媒体打开
|
||||
@ -117,9 +118,12 @@ public class VlcPlayerActivity extends BaseActivity implements MediaPlayer.Event
|
||||
break;
|
||||
case MediaPlayer.Event.Buffering: //媒体加载public float getBuffering() 获取加载视频流的进度0-100
|
||||
int Buffering = (int) event.getBuffering();
|
||||
setLoadingText("加载进度:%" + Buffering);
|
||||
if (Buffering >= 100) {
|
||||
dismissLoadingDialog();
|
||||
loading.setVisibility(View.GONE);
|
||||
}else{
|
||||
if(loading.getVisibility() == View.GONE){
|
||||
loading.setVisibility(View.VISIBLE);
|
||||
}
|
||||
}
|
||||
break;
|
||||
case MediaPlayer.Event.EndReached://媒体播放结束
|
||||
@ -131,7 +135,12 @@ public class VlcPlayerActivity extends BaseActivity implements MediaPlayer.Event
|
||||
stop();
|
||||
break;
|
||||
case MediaPlayer.Event.TimeChanged://视频时间变化
|
||||
currPlaybackTimeTrack = event.getTimeChanged();
|
||||
currItem.PositionTicks = event.getTimeChanged();
|
||||
updateTimeCount +=1;
|
||||
if(updateTimeCount > ReportCount){
|
||||
updateTimeCount = 0;
|
||||
ReportPlayState(Utils.ReportType.Progress);
|
||||
}
|
||||
break;
|
||||
case MediaPlayer.Event.PositionChanged://视频总时长的百分比
|
||||
break;
|
||||
@ -172,14 +181,11 @@ public class VlcPlayerActivity extends BaseActivity implements MediaPlayer.Event
|
||||
countTime = findViewById(R.id.countTime);
|
||||
speedBtn = findViewById(R.id.speedBtn);
|
||||
scaleBtn = findViewById(R.id.scaleBtn);
|
||||
preBtn = findViewById(R.id.preBtn);
|
||||
nextBtn = findViewById(R.id.nextBtn);
|
||||
playPauseBtn = findViewById(R.id.playPauseBtn);
|
||||
stopBtn = findViewById(R.id.stopBtn);
|
||||
pauseFlag = findViewById(R.id.pauseFlag);
|
||||
currPostion = findViewById(R.id.currPostion);
|
||||
preBtn.setOnClickListener(this);
|
||||
nextBtn.setOnClickListener(this);
|
||||
loading = findViewById(R.id.loading);
|
||||
playPauseBtn.setOnClickListener(this);
|
||||
stopBtn.setOnClickListener(this);
|
||||
pauseFlag.setOnClickListener(this);
|
||||
@ -189,9 +195,9 @@ public class VlcPlayerActivity extends BaseActivity implements MediaPlayer.Event
|
||||
boolean rv = false;
|
||||
int keycode = keyEvent.getKeyCode();
|
||||
if (keycode == KeyEvent.KEYCODE_DPAD_RIGHT) {
|
||||
rv = setTimeOnSeekBar(currPlaybackTimeTrack + (long) (mediaPlayer.getLength() * 0.05));
|
||||
rv = setTimeOnSeekBar(currItem.PositionTicks + (long) (mediaPlayer.getLength() * 0.05));
|
||||
} else if (keycode == KeyEvent.KEYCODE_DPAD_LEFT) {
|
||||
rv = setTimeOnSeekBar(currPlaybackTimeTrack - (long) (mediaPlayer.getLength() * 0.05));
|
||||
rv = setTimeOnSeekBar(currItem.PositionTicks - (long) (mediaPlayer.getLength() * 0.05));
|
||||
}
|
||||
return rv;
|
||||
}
|
||||
@ -276,7 +282,7 @@ public class VlcPlayerActivity extends BaseActivity implements MediaPlayer.Event
|
||||
public void onClick(View view) {
|
||||
playListMenu.dismiss();
|
||||
if (m.id != Utils.playIndex) {
|
||||
ReportPlayState(Utils.ReportType.stop, Utils.playList.get(Utils.playIndex).Id);
|
||||
ReportPlayState(Utils.ReportType.stop);
|
||||
Utils.playIndex = m.id;
|
||||
play();
|
||||
}
|
||||
@ -330,6 +336,16 @@ public class VlcPlayerActivity extends BaseActivity implements MediaPlayer.Event
|
||||
audioTracksBtn.setOnClickListener(this);
|
||||
}
|
||||
|
||||
private Handler mhandler = new Handler(Looper.getMainLooper());
|
||||
private Runnable mUpdateSeekBar = new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
Log.d(TAG, "run: 更新进度:" + currItem.PositionTicks);
|
||||
setSeekBar(currItem.PositionTicks);
|
||||
mhandler.postDelayed(mUpdateSeekBar,1000);
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* 显示控制器
|
||||
*/
|
||||
@ -345,39 +361,12 @@ public class VlcPlayerActivity extends BaseActivity implements MediaPlayer.Event
|
||||
ControllerTop.setVisibility(View.VISIBLE);
|
||||
}
|
||||
if (ControllerBottom.getVisibility() == View.GONE) {
|
||||
progressTime = new Timer();
|
||||
progressTime.schedule(new TimerTask() {
|
||||
@Override
|
||||
public void run() {
|
||||
mActivity.runOnUiThread(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
setSeekBar(currPlaybackTimeTrack);
|
||||
}
|
||||
});
|
||||
}
|
||||
}, 0, 1000);
|
||||
mhandler.postDelayed(mUpdateSeekBar,1000);
|
||||
ControllerBottom.setVisibility(View.VISIBLE);
|
||||
playPauseBtn.requestFocus();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 设置进度条时间
|
||||
*/
|
||||
public void setSeekBar(Long p) {
|
||||
if (ControllerBottom.getVisibility() == View.VISIBLE) {
|
||||
double i = (double) p / 1000;
|
||||
long duration = mediaPlayer.getLength();
|
||||
if (duration > 0) {
|
||||
long pos = 1000L * p / duration;
|
||||
currPostion.setProgress((int) pos);
|
||||
}
|
||||
currTime.setText(TrickToTime(p));
|
||||
countTime.setText(TrickToTime(duration));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 隐藏控制器
|
||||
*/
|
||||
@ -387,9 +376,24 @@ public class VlcPlayerActivity extends BaseActivity implements MediaPlayer.Event
|
||||
}
|
||||
if (ControllerBottom.getVisibility() == View.VISIBLE) {
|
||||
ControllerBottom.setVisibility(View.GONE);
|
||||
if (progressTime != null) {
|
||||
progressTime.cancel();
|
||||
progressTime = null;
|
||||
mhandler.removeCallbacks(mUpdateSeekBar);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 设置进度条时间
|
||||
*/
|
||||
public void setSeekBar(Long p) {
|
||||
if (ControllerBottom.getVisibility() == View.VISIBLE) {
|
||||
if(null != mediaPlayer && mediaPlayer.getLength() > 0){
|
||||
double i = (double) p / 1000;
|
||||
long duration = mediaPlayer.getLength();
|
||||
if (duration > 0) {
|
||||
long pos = 1000L * p / duration;
|
||||
currPostion.setProgress((int) pos);
|
||||
}
|
||||
currTime.setText(TrickToTime(p));
|
||||
countTime.setText(TrickToTime(duration));
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -400,9 +404,9 @@ public class VlcPlayerActivity extends BaseActivity implements MediaPlayer.Event
|
||||
public void play() {
|
||||
if (Utils.playList.size() > 0) {
|
||||
if (Utils.playIndex < Utils.playList.size()) {
|
||||
Video v = Utils.playList.get(Utils.playIndex);
|
||||
videoTitle.setText(v.Name);
|
||||
mediaPlayer.play(Uri.parse(v.Url));
|
||||
currItem = Utils.playList.get(Utils.playIndex);
|
||||
videoTitle.setText(currItem.Name);
|
||||
mediaPlayer.play(Uri.parse(currItem.Url));
|
||||
}
|
||||
} else {
|
||||
stop();
|
||||
@ -414,36 +418,17 @@ public class VlcPlayerActivity extends BaseActivity implements MediaPlayer.Event
|
||||
*/
|
||||
public void playNext() {
|
||||
if (Utils.playIndex < (Utils.playList.size() - 1)) {
|
||||
ReportPlayState(Utils.ReportType.stop, Utils.playList.get(Utils.playIndex).Id);
|
||||
ReportPlayState(Utils.ReportType.stop);
|
||||
Utils.playIndex += 1;
|
||||
play();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 上一集
|
||||
*/
|
||||
public void playPre() {
|
||||
if (Utils.playIndex > 0) {
|
||||
ReportPlayState(Utils.ReportType.stop, Utils.playList.get(Utils.playIndex).Id);
|
||||
Utils.playIndex -= 1;
|
||||
play();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 停止播放并结束Activity
|
||||
*/
|
||||
public void stop() {
|
||||
ReportPlayState(Utils.ReportType.stop, Utils.playList.get(Utils.playIndex).Id);
|
||||
if (progressTime != null) {
|
||||
progressTime.cancel();
|
||||
progressTime = null;
|
||||
}
|
||||
if (reportProcessTime != null) {
|
||||
reportProcessTime.cancel();
|
||||
progressTime = null;
|
||||
}
|
||||
ReportPlayState(Utils.ReportType.stop);
|
||||
mediaPlayer.stop();
|
||||
mediaPlayer.release();
|
||||
libVLC.release();
|
||||
@ -528,11 +513,7 @@ public class VlcPlayerActivity extends BaseActivity implements MediaPlayer.Event
|
||||
@Override
|
||||
public void onClick(View view) {
|
||||
int id = view.getId();
|
||||
if (id == R.id.nextBtn) {
|
||||
playNext();
|
||||
} else if (id == R.id.preBtn) {
|
||||
playPre();
|
||||
} else if (id == R.id.playPauseBtn) {
|
||||
if (id == R.id.playPauseBtn) {
|
||||
playOrpause();
|
||||
} else if (id == R.id.stopBtn) {
|
||||
stop();
|
||||
@ -549,33 +530,13 @@ public class VlcPlayerActivity extends BaseActivity implements MediaPlayer.Event
|
||||
}
|
||||
}
|
||||
|
||||
private void ReportPlayState(Utils.ReportType type, String Id) {
|
||||
if (type == Utils.ReportType.playing) {
|
||||
reportProcessTime = new Timer();
|
||||
reportProcessTime.schedule(new TimerTask() {
|
||||
@Override
|
||||
public void run() {
|
||||
ReportPlayState(Utils.ReportType.Progress, Utils.playList.get(Utils.playIndex).Id);
|
||||
}
|
||||
}, 1000, 10000);
|
||||
} else if (type == Utils.ReportType.stop) {
|
||||
if (reportProcessTime != null) {
|
||||
reportProcessTime.cancel();
|
||||
reportProcessTime = null;
|
||||
}
|
||||
private void ReportPlayState(Utils.ReportType type) {
|
||||
Utils.ReportPlayState(type,currItem.Id,currItem.PositionTicks);
|
||||
}
|
||||
|
||||
new Thread(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
if (type == Utils.ReportType.playing) {
|
||||
Utils.ReportPlaying(Id, currPlaybackTimeTrack);
|
||||
} else if (type == Utils.ReportType.stop) {
|
||||
Utils.ReportPlaybackStop(Id, currPlaybackTimeTrack);
|
||||
} else if (type == Utils.ReportType.Progress) {
|
||||
Utils.ReportPlaybackProgress(Id, currPlaybackTimeTrack);
|
||||
}
|
||||
}
|
||||
}).start();
|
||||
public void finish() {
|
||||
mhandler.removeCallbacksAndMessages(null);
|
||||
super.finish();
|
||||
}
|
||||
}
|
@ -95,14 +95,6 @@
|
||||
android:orientation="horizontal"
|
||||
android:paddingBottom="20dp">
|
||||
|
||||
<ImageView
|
||||
android:id="@+id/preBtn"
|
||||
android:layout_width="@dimen/button_width"
|
||||
android:layout_height="@dimen/button_height"
|
||||
android:background="@drawable/shape_user_focus"
|
||||
android:focusable="true"
|
||||
android:src="@drawable/ic_outline_skip_previous_48" />
|
||||
|
||||
<ImageView
|
||||
android:id="@+id/playPauseBtn"
|
||||
android:layout_width="@dimen/button_width"
|
||||
@ -121,15 +113,6 @@
|
||||
android:focusable="true"
|
||||
android:src="@drawable/ic_outline_stop_48" />
|
||||
|
||||
<ImageView
|
||||
android:id="@+id/nextBtn"
|
||||
android:layout_width="@dimen/button_width"
|
||||
android:layout_height="@dimen/button_height"
|
||||
android:layout_marginLeft="@dimen/button_margin_left"
|
||||
android:background="@drawable/shape_user_focus"
|
||||
android:focusable="true"
|
||||
android:src="@drawable/ic_outline_skip_next_48" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/speedBtn"
|
||||
android:layout_width="wrap_content"
|
||||
@ -187,14 +170,6 @@
|
||||
</LinearLayout>
|
||||
</FrameLayout>
|
||||
|
||||
<ImageView
|
||||
android:id="@+id/loading"
|
||||
android:layout_width="160dp"
|
||||
android:layout_height="160dp"
|
||||
android:layout_gravity="center"
|
||||
android:src="@android:drawable/ic_input_get"
|
||||
android:visibility="gone" />
|
||||
|
||||
<ImageView
|
||||
android:id="@+id/pauseFlag"
|
||||
android:layout_width="160dp"
|
||||
@ -202,4 +177,10 @@
|
||||
android:layout_gravity="center"
|
||||
android:src="@drawable/ic_baseline_pause_circle_outline_48"
|
||||
android:visibility="gone" />
|
||||
|
||||
<ProgressBar
|
||||
android:id="@+id/loading"
|
||||
android:layout_width="160dp"
|
||||
android:layout_height="160dp"
|
||||
android:layout_gravity="center" />
|
||||
</FrameLayout>
|
Loading…
x
Reference in New Issue
Block a user