我正在尝试创建引擎和输出Mix:
// create engine
this->res = slCreateEngine(&this->engineObject, 0, NULL, 0, NULL, NULL);
if (SL_RESULT_SUCCESS != this->res)
{
LOGI("Can't Create Engine.");
this->Free();
return;
}
this->res = (*this->engineObject)->Realize(this->engineObject, SL_BOOLEAN_FALSE);
if (SL_RESULT_SUCCESS != this->res)
{
LOGI("Can't Realize Engine.");
this->Free();
return;
}
this->res = (*this->engineObject)->GetInterface(this->engineObject, SL_IID_ENGINE, &this->engineEngine);
if (SL_RESULT_SUCCESS != this->res)
{
LOGI("Can't GetInterface Engine.");
this->Free();
return;
}
// create output mix
this->res = (*this->engineEngine)->CreateOutputMix(this->engineEngine, &this->outputmixObject, 0, NULL, NULL);
if (SL_RESULT_SUCCESS != this->res)
{
LOGI("Can't Create Output Mix.");
this->Free();
return;
}
this->res = (*this->outputmixObject)->Realize(this->outputmixObject, SL_BOOLEAN_FALSE);
if (SL_RESULT_SUCCESS != this->res)
{
LOGI("Can't Realize Output Mix.");
this->Free();
return;
}
这是成功的!
从IceCast开始播放mp3流 (例如" http://example.com/stream320"):
SLDataLocator_URI loc_uri = {SL_DATALOCATOR_URI, filename};
SLDataFormat_MIME format_mime = {SL_DATAFORMAT_MIME, (SLchar*)NULL, SL_CONTAINERTYPE_UNSPECIFIED};
SLDataSource audioSrcuri = {&loc_uri, &format_mime};
SLDataLocator_OutputMix dataLocatorOut = {SL_DATALOCATOR_OUTPUTMIX,this->outputmixObject};
SLDataSink audioSnk = {&dataLocatorOut, NULL};
const SLInterfaceID pIDs[3] = {SL_IID_PLAY, SL_IID_SEEK, SL_IID_PREFETCHSTATUS};
const SLboolean pIDsRequired[3] = {SL_BOOLEAN_TRUE, SL_BOOLEAN_TRUE, SL_BOOLEAN_TRUE};
this->res = (*this->engineEngine)->CreateAudioPlayer(this->engineEngine, &this->player, &audioSrcuri, &audioSnk, 3, pIDs, pIDsRequired);
if (SL_RESULT_SUCCESS != this->res)
{
LOGI("Can't Create Audio Player.");
return;
}
this->res = (*this->player)->Realize(this->player, SL_BOOLEAN_FALSE);
if (SL_RESULT_SUCCESS != this->res)
{
LOGI("Can't Realize Audio Player.");
return;
}
this->res = (*this->player)->GetInterface(this->player, SL_IID_PLAY, &this->playerInterface);
if (SL_RESULT_SUCCESS != this->res)
{
LOGI("Can't Get Interface \"SL_IID_PLAY\" from Audio Player.");
return;
}
this->res = (*this->player)->GetInterface(this->player, SL_IID_SEEK, &this->seekInterface);
if (SL_RESULT_SUCCESS != this->res)
{
LOGI("Can't Get Interface \"SL_IID_SEEK\" from Audio Player.");
return;
}
this->res = (*this->player)->GetInterface(this->player, SL_IID_PREFETCHSTATUS, &this->prefetchInterface);
if (SL_RESULT_SUCCESS != this->res)
{
LOGI("Can't Get Interface \"SL_IID_PREFETCHSTATUS\" from Audio Player.");
return;
}
this->res = (*this->playerInterface)->SetPlayState(this->playerInterface, SL_PLAYSTATE_PAUSED);
if (SL_RESULT_SUCCESS != this->res)
{
LOGI("Can't Set Play State \"SL_PLAYSTATE_PAUSED\".");
return;
}
this->LastPlayState = SL_PLAYSTATE_PAUSED;
/*SLuint32 prefetchStatus = SL_PREFETCHSTATUS_UNDERFLOW;
while (prefetchStatus != SL_PREFETCHSTATUS_SUFFICIENTDATA)
{
LOGI("Wait until there's data to play...");
usleep(1 * 1000);
(*this->prefetchInterface)->GetPrefetchStatus(this->prefetchInterface, &prefetchStatus);
}
LOGI("Data OK.");
/* Get duration */
SLmillisecond durationInMsec = SL_TIME_UNKNOWN;
this->res = (*this->playerInterface)->GetDuration(this->playerInterface, &durationInMsec);
if (SL_RESULT_SUCCESS != this->res)
{
LOGI("Can't Get Duration.");
return;
}
if (durationInMsec == SL_TIME_UNKNOWN) {
LOGI("durationInMsec = SL_TIME_UNKNOWN");
//durationInMsec = 5000;
}
(*this->seekInterface)->SetLoop(this->seekInterface,SL_BOOLEAN_FALSE,0,SL_TIME_UNKNOWN);
filename =" http://example.com/stream320&#34 ;;
LogCat开始打印错误消息...:
E / libOpenSLES(16432):MEDIA_BUFFERING_UPDATE -491520000%< 0 E / libOpenSLES(16432):MEDIA_BUFFERING_UPDATE -655360000%< 0 E / libOpenSLES(16432):MEDIA_BUFFERING_UPDATE -819200000%< 0 ...
但正在播放流! 好的,所以我试着停止玩:
this->res = (*this->playerInterface)->SetPlayState(this->playerInterface, SL_PLAYSTATE_STOPPED);
if (SL_RESULT_SUCCESS != this->res)
LOGI("Can't Set Play State \"SL_PLAYSTATE_STOPPED\".");
OK!播放确实已停止,但播放器继续下载流。 ???
所以我试试破坏PlayerObj:
(*this->player)->Destroy(this->player);
LogCat打印错误消息:
// system / bin / app_process(16690):检测到堆栈损坏:已中止
并且应用程序进程终止。 有什么问题?