case 'play':
{
//从消息msg的"result"得到result的值
int32_t result;
CHECK(msg->findInt32("result", &result));
ALOGI("PLAY completed with result %d (%s)",
result, strerror(-result));
if (result == OK) {
//如果result == OK
//说明成功收到了服务端发送来的对应于play的应答消息
//从消息msg的"response"字段获取到应答消息对象response
sp<RefBase> obj;
CHECK(msg->findObject("response", &obj));
sp<ARTSPResponse> response =
static_cast<ARTSPResponse *>(obj.get());
if (response->mStatusCode != 200) {
//如果应答消息的状态码不为200
//则将错误码UNKNOWN_ERROR赋值给result
result = UNKNOWN_ERROR;
} else {
//代码执行到这里说明应答消息的状态码为200
//调用parsePlayResponse(response)函数解析应答消息对象
//具体的解析过程后续介绍
parsePlayResponse(response);
//新建消息timeout
//消息名'tiou'
//消息处理者为this也即MyHandler
sp<AMessage> timeout = new AMessage('tiou', this);
//将超时检查标识mCheckTimeoutGeneration自增1
//并添加到timeout消息的"tioucheck"字段
//发送该timeout消息
mCheckTimeoutGeneration++;
timeout->setInt32("tioucheck", mCheckTimeoutGeneration);
timeout->post(kStartupTimeoutUs);
}
}
if (result != OK) {
//如果上述过程中result != OK
//则需要发送消息名为'disc'的消息取消连接
sp<AMessage> reply = new AMessage('disc', this);
mConn->disconnect(reply);
}
break;
}
MyHandler对'play'消息的处理
最新推荐文章于 2024-09-21 22:04:29 发布