Skip to content

Commit

Permalink
feat(iOS): add interface to sync player
Browse files Browse the repository at this point in the history
  • Loading branch information
skufly authored and pingkai committed Apr 28, 2020
1 parent ade893f commit d02f881
Show file tree
Hide file tree
Showing 3 changed files with 103 additions and 0 deletions.
24 changes: 24 additions & 0 deletions platform/Apple/source/CicadaDef.h
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,30 @@ typedef enum CicadaOption: NSUInteger {
CICADA_OPTION_RENDER_FPS = 0,
} CicadaOption;

typedef enum CicadaPlaybackType: NSUInteger {
/**
* @brief 播放音视频,默认值
*/
/****
* @brief play video & audio, default
*/
CicadaPlaybackTypeALL = 0,
/**
* @brief 播放视频
*/
/****
* @brief play video
*/
CicadaPlaybackTypeVideo = 1,
/**
* @brief 播放音频
*/
/****
* @brief play audio
*/
CicadaPlaybackTypeAudio = 2,
} CicadaPlaybackType;

/**
@brief CicadaErrorModel为播放错误信息描述
*/
Expand Down
31 changes: 31 additions & 0 deletions platform/Apple/source/CicadaPlayer.h
Original file line number Diff line number Diff line change
Expand Up @@ -285,6 +285,37 @@ OBJC_EXPORT
*/
-(void) setDefaultBandWidth:(int)bandWidth;

/**
@brief 设置所需的播放内容。
@param CicadaPlaybackType 指定播放音频或视频。
*/
/****
@brief Set the playback track.
@param CicadaPlaybackType The specified track to playback.
*/
-(void) setPlaybackType:(CicadaPlaybackType)type;

/**
@brief 获取当前播放的pts。
@return 当前播放的pts。
*/
/****
@brief Get playing pts.
@return Playing pts.
*/
-(int64_t) getPlayingPts;


/**
@brief 设置参考时间钟。
@param referClock 参考时间钟。
*/
/****
@brief Set the refer clock
@param referClock The refer clock
*/
-(void) SetClockRefer:(int64_t (^)(void))referClock;

/**
* @brief 获取播放器的参数
*
Expand Down
48 changes: 48 additions & 0 deletions platform/Apple/source/CicadaPlayer.mm
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,8 @@ static void CicadaPlayer_log_print(void *userData, int prio, const char *buf)
}
}

typedef int64_t(^CicadaReferClockFun) ();

@interface CicadaPlayer () <CicadaPlayerViewDelegate>
{
CicadaPlayerView* mView;
Expand All @@ -64,6 +66,7 @@ @interface CicadaPlayer () <CicadaPlayerViewDelegate>
@property(nonatomic,assign) CicadaStatus mCurrentStatus;
@property(nonatomic, strong) NSString *traceId;
@property(nonatomic, strong) CicadaThumbnail* thumbnail;
@property(nonatomic, strong) CicadaReferClockFun referClock;
@end

@implementation CicadaPlayer
Expand All @@ -73,6 +76,7 @@ @implementation CicadaPlayer
@synthesize currentPosition = _currentPosition;
@synthesize bufferedPosition = _bufferedPosition;
@synthesize duration = _duration;
@synthesize referClock = _referClock;

- (void)resetProperty
{
Expand Down Expand Up @@ -843,6 +847,50 @@ - (void) setDelegate:(id<CicadaDelegate>)theDelegate
}
}

-(void) setPlaybackType:(CicadaPlaybackType)type
{
if (self.player) {
uint64_t flags = 0;
switch (type) {
case CicadaPlaybackTypeVideo:
flags = (1 << CICADA_TRACK_VIDEO);
break;
case CicadaPlaybackTypeAudio:
flags = (1 << CICADA_TRACK_AUDIO);
break;
default:
flags = (1 << CICADA_TRACK_VIDEO) | (1 << CICADA_TRACK_AUDIO);
break;
}
self.player->SetStreamTypeFlags(flags);
}
}

-(int64_t) getPlayingPts
{
if (self.player) {
self.player->GetMasterClockPts();
}
return 0;
}

int64_t CicadaClockRefer(void *arg)
{
CicadaPlayer *player = (__bridge CicadaPlayer *)arg;
if (player.referClock) {
return player.referClock();
}
return -1;
}

-(void) SetClockRefer:(int64_t (^)(void))referClock
{
if (self.player) {
self.player->SetClockRefer(CicadaClockRefer, (__bridge void*)self);
}
self.referClock = referClock;
}

-(NSString *) getOption:(CicadaOption)key
{
if (nullptr == self.player) {
Expand Down

0 comments on commit d02f881

Please sign in to comment.