#include <ctime>
int decode_interrupt_cb(void *tm)
{
time_t startTime = *(time_t*)tm;//先转为time_t指针,再取值
if (startTime > 0) {
if (time(NULL) - startTime > 3) {
// 等待超过3s则中断
return 1;
}
}
return 0;
}
bool native_startPlay(const char* path)
{
avformat_network_init();
time_t startTime = time(NULL);
int ret = -1;
ctx = avformat_alloc_context();
ctx->interrupt_callback.callback = decode_interrupt_cb;//回调函数
ctx->interrupt_callback.opaque = &startTime;//回调函数传参
ret = avformat_open_input(&ctx, path, NULL, NULL);
if (ret != 0)
return false;
......
}
08-12
236
02-02