lm3515 / ijkplayer-track Goto Github PK
View Code? Open in Web Editor NEW通过ijkplayer实现切换音轨,适用于iOS、android
通过ijkplayer实现切换音轨,适用于iOS、android
对于这个代码的解释有疑问:
//传递两个参数tracksNum:音轨的个数,stream_index:第几个音轨
ffp_set_stream_selected(ffp, tracksNum, stream_index);
我的理解:
//传递两个参数selected:切换为该音轨或者关闭该音轨,stream:第几个音轨
int ffp_set_stream_selected(FFPlayer *ffp, int stream, int selected)
{
VideoState *is = ffp->is;
AVFormatContext *ic = NULL;
AVCodecParameters *codecpar = NULL;
if (!is)
return -1;
ic = is->ic;
if (!ic)
return -1;
if (stream < 0 || stream >= ic->nb_streams) {
av_log(ffp, AV_LOG_ERROR, "invalid stream index %d >= stream number (%d)\n", stream, ic->nb_streams);
return -1;
}
codecpar = ic->streams[stream]->codecpar;
if (selected) {
//如果选择该sream,则会先关闭当前的音轨,并打开stream指向的音轨,然后返回打开音轨函数的返回值
switch (codecpar->codec_type) {
case AVMEDIA_TYPE_VIDEO:
if (stream != is->video_stream && is->video_stream >= 0)
stream_component_close(ffp, is->video_stream);
break;
case AVMEDIA_TYPE_AUDIO:
if (stream != is->audio_stream && is->audio_stream >= 0)
stream_component_close(ffp, is->audio_stream);
break;
case AVMEDIA_TYPE_SUBTITLE:
if (stream != is->subtitle_stream && is->subtitle_stream >= 0)
stream_component_close(ffp, is->subtitle_stream);
break;
default:
av_log(ffp, AV_LOG_ERROR, "select invalid stream %d of video type %d\n", stream, codecpar->codec_type);
return -1;
}
return stream_component_open(ffp, stream);
} else {
//如果没有选择,则会执行以下代码关闭该音轨,并返回0
switch (codecpar->codec_type) {
case AVMEDIA_TYPE_VIDEO:
if (stream == is->video_stream)
stream_component_close(ffp, is->video_stream);
break;
case AVMEDIA_TYPE_AUDIO:
if (stream == is->audio_stream)
stream_component_close(ffp, is->audio_stream);
break;
case AVMEDIA_TYPE_SUBTITLE:
if (stream == is->subtitle_stream)
stream_component_close(ffp, is->subtitle_stream);
break;
default:
av_log(ffp, AV_LOG_ERROR, "select invalid stream %d of audio type %d\n", stream, codecpar->codec_type);
return -1;
}
return 0;
}
}
Hi friend, thank you for this, but i have a question : Do I need to recompile again with ./compile-ffmpeg.sh ? Or just ./compile-ijk.sh
文件放在哪里使用,可以实现音轨切换?
大神你好,切换音轨时播放的音乐卡顿,有办法解决么?
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.