mirror of
https://github.com/sifacaii/VlcJellyfin
synced 2025-05-26 06:20:20 -04:00
优化播放控制
This commit is contained in:
parent
4219760f08
commit
68cc5eee2c
@ -15,6 +15,7 @@ import android.view.Menu;
|
||||
import android.view.View;
|
||||
import android.widget.LinearLayout;
|
||||
import android.widget.TextView;
|
||||
import android.widget.Toast;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.appcompat.app.AppCompatActivity;
|
||||
@ -131,4 +132,13 @@ public class BaseActivity extends AppCompatActivity implements CustomAdapt {
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public void ShowToask(String msg){
|
||||
mAA.runOnUiThread(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
Toast.makeText(mAA,msg,Toast.LENGTH_LONG).show();
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
@ -155,10 +155,9 @@ public class Utils {
|
||||
|
||||
/**
|
||||
* 报告播放进度
|
||||
* @param paused
|
||||
* @param PositionTicks
|
||||
*/
|
||||
public static void ReportPlaybackProgress(String Id,boolean paused, long PositionTicks) {
|
||||
public static void ReportPlaybackProgress(String Id,long PositionTicks) {
|
||||
String json = "{\"itemId\" : \"" + Id + "\",\"positionTicks\": \"" + PositionTicks * 10000 + "\"}";
|
||||
//JsonObject rjo = new JsonObject();
|
||||
//rjo.addProperty("itemId",Id);
|
||||
|
@ -13,9 +13,12 @@ import android.widget.PopupMenu;
|
||||
import android.widget.RelativeLayout;
|
||||
import android.widget.SeekBar;
|
||||
import android.widget.TextView;
|
||||
import android.widget.Toast;
|
||||
|
||||
import org.videolan.libvlc.LibVLC;
|
||||
import org.videolan.libvlc.Media;
|
||||
import org.videolan.libvlc.MediaPlayer;
|
||||
import org.videolan.libvlc.interfaces.IMedia;
|
||||
import org.videolan.libvlc.util.VLCVideoLayout;
|
||||
|
||||
import java.util.Timer;
|
||||
@ -67,9 +70,6 @@ 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 ReportTime = 20; // 报告进度间隔次数
|
||||
private int ReportVal = 0; //累积次数
|
||||
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
@ -129,6 +129,8 @@ public class VlcPlayerActivity extends BaseActivity implements MediaPlayer.Event
|
||||
break;
|
||||
case MediaPlayer.Event.EncounteredError://媒体播放错误
|
||||
Log.d(TAG, "onEvent: EncounteredError");
|
||||
ShowToask("播放错误!");
|
||||
stop();
|
||||
break;
|
||||
case MediaPlayer.Event.TimeChanged://视频时间变化
|
||||
currPlaybackTimeTrack = event.getTimeChanged();
|
||||
@ -136,6 +138,7 @@ public class VlcPlayerActivity extends BaseActivity implements MediaPlayer.Event
|
||||
case MediaPlayer.Event.PositionChanged://视频总时长的百分比
|
||||
break;
|
||||
case MediaPlayer.Event.SeekableChanged:
|
||||
Log.d(TAG, "onEvent: SeekableChanged:" + event.getSeekable());
|
||||
break;
|
||||
case MediaPlayer.Event.PausableChanged:
|
||||
Log.d(TAG, "onEvent: PausableChanged");
|
||||
@ -315,7 +318,7 @@ public class VlcPlayerActivity extends BaseActivity implements MediaPlayer.Event
|
||||
private void initAudioTrackMenu(MediaPlayer.TrackDescription[] audioTrackList) {
|
||||
audioTrackMenu = new PopMenu(this, audioTracksBtn);
|
||||
for (int i = 0; i < audioTrackList.length; i++) {
|
||||
PopMenu.menu m = audioTrackMenu.add(Type_SubtitleTrack, audioTrackList[i].id, i, audioTrackList[i].name);
|
||||
PopMenu.menu m = audioTrackMenu.add(Type_AudioTrack, audioTrackList[i].id, i, audioTrackList[i].name);
|
||||
m.v.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View view) {
|
||||
@ -412,17 +415,19 @@ public class VlcPlayerActivity extends BaseActivity implements MediaPlayer.Event
|
||||
* 播放下一集
|
||||
*/
|
||||
public void playNext() {
|
||||
ReportPlayState(Utils.ReportType.stop, Utils.playList.get(Utils.playIndex).Id);
|
||||
Utils.playIndex += 1;
|
||||
play();
|
||||
if(Utils.playIndex < (Utils.playList.size() - 1)){
|
||||
ReportPlayState(Utils.ReportType.stop, Utils.playList.get(Utils.playIndex).Id);
|
||||
Utils.playIndex += 1;
|
||||
play();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 上一集
|
||||
*/
|
||||
public void playPre() {
|
||||
ReportPlayState(Utils.ReportType.stop, Utils.playList.get(Utils.playIndex).Id);
|
||||
if (Utils.playIndex > 0) {
|
||||
ReportPlayState(Utils.ReportType.stop, Utils.playList.get(Utils.playIndex).Id);
|
||||
Utils.playIndex -= 1;
|
||||
play();
|
||||
}
|
||||
@ -437,6 +442,10 @@ public class VlcPlayerActivity extends BaseActivity implements MediaPlayer.Event
|
||||
progressTime.cancel();
|
||||
progressTime = null;
|
||||
}
|
||||
if (reportProcessTime != null){
|
||||
reportProcessTime.cancel();
|
||||
progressTime = null;
|
||||
}
|
||||
mediaPlayer.stop();
|
||||
mediaPlayer.release();
|
||||
libVLC.release();
|
||||
@ -567,7 +576,7 @@ public class VlcPlayerActivity extends BaseActivity implements MediaPlayer.Event
|
||||
Utils.ReportPlaybackStop(Id, currPlaybackTimeTrack);
|
||||
} else if (type == Utils.ReportType.Progress) {
|
||||
Log.d(TAG, "run: 报告时空:" + currPlaybackTimeTrack);
|
||||
Utils.ReportPlaybackProgress(Id, !mediaPlayer.isPlaying(), currPlaybackTimeTrack);
|
||||
Utils.ReportPlaybackProgress(Id, currPlaybackTimeTrack);
|
||||
}
|
||||
}
|
||||
}).start();
|
||||
|
Loading…
Reference in New Issue
Block a user