本文整理汇总了C++中Media::hasMember方法的典型用法代码示例。如果您正苦于以下问题:C++ Media::hasMember方法的具体用法?C++ Media::hasMember怎么用?C++ Media::hasMember使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Media
的用法示例。
在下文中一共展示了Media::hasMember方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: sendFile
bool SampleService::sendFile(BtpAction* action, FileInfo& fi)
{
bool rval = false;
// FIXME: only audio supported at this time
// FIXME: get content type for file info instead of "extension"
const char* extension = fi["extension"]->getString();
if((rval = (strcmp(extension, "mp3") == 0)))
{
// ensure file exists, get sample range for media
File file(fi["path"]->getString());
Media media;
BM_ID_SET(media["id"], BM_MEDIA_ID(fi["mediaId"]));
if((rval = (file->exists() && getSampleRange(media))))
{
// set up response header
HttpResponseHeader* header = action->getResponse()->getHeader();
header->setField("Content-Type", "audio/mpeg");
header->setField(
"Content-Disposition", "attachment; filename=bitmunk-sample.mp3");
// calculate content length for sample for HTTP/1.0
if(strcmp(
action->getRequest()->getHeader()->getVersion(), "HTTP/1.0") == 0)
{
// check for cached sample content length
int64_t contentLength = 0;
if(media->hasMember("sampleContentLength"))
{
contentLength = media["sampleContentLength"]->getUInt64();
}
else
{
// create time parser to produce sample
MpegAudioTimeParser matp;
matp.addTimeSet(
media["sampleRange"][0]->getUInt32(),
media["sampleRange"][1]->getUInt32());
// FIXME: build a method into the catalog that will return
// the content-length for a sample
// read data, strip id3 tag, parse mp3 data, add new id3 tag
// get content length
Id3v2Tag tag(media);
Id3v2TagWriter stripper(NULL);
Id3v2TagWriter embedder(
&tag, false, tag.getFrameSource(), false);
FileInputStream fis(file);
MutatorInputStream strip(&fis, false, &stripper, false);
MutatorInputStream parse(&strip, false, &matp, false);
MutatorInputStream embed(&parse, false, &embedder, false);
int64_t numBytes;
while((numBytes = embed.skip(file->getLength())) > 0)
{
contentLength += numBytes;
}
embed.close();
if(numBytes != -1)
{
// cache content length
media["sampleContentLength"] = contentLength;
}
}
// replace chunked encoding with content length
header->setField("Connection", "close");
header->removeField("Transfer-Encoding");
header->removeField("TE");
header->setField("Content-Length", contentLength);
}
// create time parser to produce sample
MpegAudioTimeParser matp;
matp.addTimeSet(
media["sampleRange"][0]->getUInt32(),
media["sampleRange"][1]->getUInt32());
// read data, strip id3 tag, embed new id3 tag, produce sample
Id3v2Tag tag(media);
Id3v2TagWriter stripper(NULL);
Id3v2TagWriter embedder(
&tag, false, tag.getFrameSource(), false);
FileInputStream fis(file);
MutatorInputStream strip(&fis, false, &stripper, false);
MutatorInputStream parse(&strip, false, &matp, false);
MutatorInputStream embed(&parse, false, &embedder, false);
// send sample, remove any special encoding to prevent compression
action->getRequest()->getHeader()->removeField("Accept-Encoding");
action->getResponse()->getHeader()->setStatus(200, "OK");
action->sendResult(&embed);
// close stream
embed.close();
}
//.........这里部分代码省略.........