mirror of
https://github.com/ZLMediaKit/ZLMediaKit.git
synced 2024-11-23 11:17:09 +08:00
mk_player api 增加seek和获取进度以相对开始时间的接口以适应按时间轴方式回放的需求
This commit is contained in:
parent
12eabbe426
commit
98d0bc27f9
@ -80,6 +80,13 @@ API_EXPORT void API_CALL mk_player_pause(mk_player ctx, int pause);
|
||||
*/
|
||||
API_EXPORT void API_CALL mk_player_seekto(mk_player ctx, float progress);
|
||||
|
||||
/**
|
||||
* 设置点播进度条
|
||||
* @param ctx 对象指针
|
||||
* @param seekPos 取值范围 相对于开始时间增量 单位秒
|
||||
*/
|
||||
API_EXPORT void API_CALL mk_player_seektoByPos(mk_player ctx, int seekPos);
|
||||
|
||||
/**
|
||||
* 设置播放器开启播放结果回调函数
|
||||
* @param ctx 播放器指针
|
||||
@ -155,10 +162,15 @@ API_EXPORT int API_CALL mk_player_audio_channel(mk_player ctx);
|
||||
API_EXPORT float API_CALL mk_player_duration(mk_player ctx);
|
||||
|
||||
/**
|
||||
* 获取点播播放进度,取值范围未 0.0~1.0
|
||||
* 获取点播播放进度,取值范围 0.0~1.0
|
||||
*/
|
||||
API_EXPORT float API_CALL mk_player_progress(mk_player ctx);
|
||||
|
||||
/**
|
||||
* 获取点播播放进度位置,取值范围 相对于开始时间增量 单位秒
|
||||
*/
|
||||
API_EXPORT int API_CALL mk_player_progress_pos(mk_player ctx);
|
||||
|
||||
/**
|
||||
* 获取丢包率,rtsp时有效
|
||||
* @param ctx 对象指针
|
||||
|
@ -62,6 +62,16 @@ API_EXPORT void API_CALL mk_player_seekto(mk_player ctx, float progress) {
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
API_EXPORT void API_CALL mk_player_seektoByPos(mk_player ctx, int seekPos)
|
||||
{
|
||||
MediaPlayer::Ptr& player = *((MediaPlayer::Ptr*)ctx);
|
||||
player->getPoller()->async([seekPos, player]() {
|
||||
//切换线程后再操作
|
||||
player->seekTo((uint32_t)seekPos);
|
||||
});
|
||||
}
|
||||
|
||||
static void mk_player_set_on_event(mk_player ctx, on_mk_play_event cb, void *user_data, int type) {
|
||||
assert(ctx && cb);
|
||||
MediaPlayer::Ptr &player = *((MediaPlayer::Ptr *)ctx);
|
||||
@ -169,6 +179,14 @@ API_EXPORT float API_CALL mk_player_progress(mk_player ctx) {
|
||||
return player->getProgress();
|
||||
}
|
||||
|
||||
|
||||
API_EXPORT int API_CALL mk_player_progress_pos(mk_player ctx)
|
||||
{
|
||||
assert(ctx);
|
||||
MediaPlayer::Ptr& player = *((MediaPlayer::Ptr*)ctx);
|
||||
return player->getProgressPos();
|
||||
}
|
||||
|
||||
API_EXPORT float API_CALL mk_player_loss_rate(mk_player ctx, int track_type) {
|
||||
assert(ctx);
|
||||
MediaPlayer::Ptr &player = *((MediaPlayer::Ptr *)ctx);
|
||||
|
@ -52,7 +52,10 @@ void Stamp::revise(int64_t dts, int64_t pts, int64_t &dts_out, int64_t &pts_out,
|
||||
//这是点播
|
||||
dts_out = dts;
|
||||
pts_out = pts;
|
||||
_relativeStamp = dts_out;
|
||||
_last_dts = dts;
|
||||
if (_dts_base == -1)
|
||||
_dts_base = dts;
|
||||
_relativeStamp = _npt_base + dts - _dts_base;
|
||||
return;
|
||||
}
|
||||
|
||||
@ -84,6 +87,8 @@ void Stamp::revise(int64_t dts, int64_t pts, int64_t &dts_out, int64_t &pts_out,
|
||||
}
|
||||
|
||||
void Stamp::setRelativeStamp(int64_t relativeStamp) {
|
||||
_dts_base = _last_dts;
|
||||
_npt_base = relativeStamp;
|
||||
_relativeStamp = relativeStamp;
|
||||
}
|
||||
|
||||
|
@ -71,6 +71,9 @@ private:
|
||||
int64_t _last_dts = -1;
|
||||
SmoothTicker _ticker;
|
||||
bool _playback = false;
|
||||
|
||||
int64_t _dts_base = 0;
|
||||
int64_t _npt_base = 0;
|
||||
};
|
||||
|
||||
|
||||
|
@ -93,12 +93,24 @@ public:
|
||||
*/
|
||||
virtual float getProgress() const { return 0;}
|
||||
|
||||
/**
|
||||
* 获取播放进度pos,取值 相对开始时间增量 单位秒
|
||||
* @return
|
||||
*/
|
||||
virtual uint32_t getProgressPos() const { return 0; }
|
||||
|
||||
/**
|
||||
* 拖动进度条
|
||||
* @param fProgress 进度,取值 0.0 ~ 1.0
|
||||
*/
|
||||
virtual void seekTo(float fProgress) {}
|
||||
|
||||
/**
|
||||
* 拖动进度条
|
||||
* @param seekPos 进度,取值 相对于开始时间的增量 单位秒
|
||||
*/
|
||||
virtual void seekTo(uint32_t seekPos) {}
|
||||
|
||||
/**
|
||||
* 设置一个MediaSource,直接生产rtsp/rtmp代理
|
||||
* @param src
|
||||
@ -174,6 +186,12 @@ public:
|
||||
}
|
||||
return Parent::getProgress();
|
||||
}
|
||||
uint32_t getProgressPos() const override {
|
||||
if (_delegate) {
|
||||
return _delegate->getProgressPos();
|
||||
}
|
||||
return Parent::getProgressPos();
|
||||
}
|
||||
void seekTo(float fProgress) override{
|
||||
if (_delegate) {
|
||||
return _delegate->seekTo(fProgress);
|
||||
@ -181,6 +199,13 @@ public:
|
||||
return Parent::seekTo(fProgress);
|
||||
}
|
||||
|
||||
void seekTo(uint32_t seekPos) override {
|
||||
if (_delegate) {
|
||||
return _delegate->seekTo(seekPos);
|
||||
}
|
||||
return Parent::seekTo(seekPos);
|
||||
}
|
||||
|
||||
void setMediaSouce(const MediaSource::Ptr & src) override {
|
||||
if (_delegate) {
|
||||
_delegate->setMediaSouce(src);
|
||||
|
Loading…
Reference in New Issue
Block a user