本文整理汇总了C++中AudioPlayer::play方法的典型用法代码示例。如果您正苦于以下问题:C++ AudioPlayer::play方法的具体用法?C++ AudioPlayer::play怎么用?C++ AudioPlayer::play使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类AudioPlayer
的用法示例。
在下文中一共展示了AudioPlayer::play方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: main
int main(int ac, char **av)
{
if (ac == 3) {
AudioPlayer p;
try {
std::cout << "Playing " << av[1] << "..." << std::endl;
p.loadFile(av[1]);
p.play();
std::cout << "Playing " << av[1] << "..." << std::endl;
p.play();
std::cout << "Playing " << av[2] << "..." << std::endl;
p.loadFile(av[2]);
p.play();
p.destroySource();
}
catch (const AudioPlayer::Exception& e) {
std::cout << "AudioPlayer error: " << e.what() << std::endl;
p.cleanUp();
}
}
else
std::cout << "./audio FILE FILE" << std::endl;
}
示例2: playASound
int playASound(const char* fn){
AudioPlayer* ap = AudioPlayer::file(fn);
if(!ap) {
std::cerr << "Error loading audio" << std::endl;
return 1;
}
ap->play();
char indic[] = { '|', '/', '-', '\\' };
int i = 0;
do { // 5
// std::cout << "Loop." << std::endl;
CFRunLoopRunInMode ( // 6
kCFRunLoopDefaultMode, // 7
0.25, // 8
false // 9
);
std::cout << "\rPlaying.. " << indic[i];
double d = ap->progress();
double min = floor(d/60);
double sec = floor(fmod(d,60));
std::cout << " " << min << ":" << sec;
d = ap->duration();
min = floor(d/60);
sec = floor(fmod(d,60));
std::cout << " " << min << ":" << sec;
std::cout << std::flush;
if(ap->progress() > 5) {
ap->seek(rand()/(float(RAND_MAX))*ap->duration());
}
i = (i+1)%4;
} while (ap->isPlaying());
delete ap;
return 1;
}
示例3: audioPlayerTest
void AudioEngine::audioPlayerTest(const int sleep) noexcept
{
int audioId = -1;
bool leftPlaying = false;
AudioPlayer *sound = nullptr;
std::string soundPath = "";
while (!_stopGc)
{
if (audioId != -1)
{
std::lock_guard<std::mutex> lock(_playersMutex);
const auto &it = _players.find(audioId);
if (it != _players.end())
{
it->second->stop();
audioId = -1;
}
}
if (!leftPlaying)
{
soundPath = "cse_dialog1.ogg";
}
else
{
soundPath = "cse_dialog2.ogg";
}
leftPlaying = !leftPlaying;
sound = createPlayerWithPath(soundPath, 1.f, true);
if (sound != nullptr)
{
sound->play();
audioId = sound->getPlayerId();
}
std::this_thread::yield();
std::this_thread::sleep_for(std::chrono::milliseconds(sleep));
}
}
示例4: main
int main() {
const char *fn = "WRECKINGBALL.wav";
AudioPlayer* ap = AudioPlayer::file(fn);
if(!ap) {
std::cerr << "Error loading audio" << std::endl;
return 1;
}
ap->play();
char indic[] = { '|', '/', '-', '\\' };
int i = 0;
do { // 5
// std::cout << "Loop." << std::endl;
CFRunLoopRunInMode ( // 6
kCFRunLoopDefaultMode, // 7
0.25, // 8
false // 9
);
std::cout << "\rPlaying.. " << indic[i];
double d = ap->progress();
double min = floor(d/60);
double sec = floor(fmod(d,60));
std::cout << " " << min << ":" << sec;
d = ap->duration();
min = floor(d/60);
sec = floor(fmod(d,60));
std::cout << " " << min << ":" << sec;
std::cout << std::flush;
if(ap->progress() > 5) {
ap->seek(rand()/(float(RAND_MAX))*ap->duration());
}
i = (i+1)%4;
} while (ap->isPlaying());
delete ap;
#if 0
// std::cout << "dataformat " << aqData.mDataFormat << std::endl;
std::cout << "bufferbytesize " << aqData.bufferByteSize << std::endl;
std::cout << "numpacketstoread " << aqData.mNumPacketsToRead << std::endl;
std::cout << "maxpacketsz " << maxPacketSize << std::endl;
std::cout << "df bpp " << aqData.mDataFormat.mBytesPerPacket << std::endl;
std::cout << "df fpp " << aqData.mDataFormat.mFramesPerPacket << std::endl;
unsigned int running =0;
sz = 4;
status = AudioFileGetProperty ( // 9
aqData.mAudioFile, // 10
kAudioQueueProperty_IsRunning , // 11
&running, // 12
&sz // 13
);
std::cout << "Running: " << running << std::endl;
running =0;
sz = 4;
status = AudioFileGetProperty ( // 9
aqData.mAudioFile, // 10
kAudioQueueProperty_IsRunning , // 11
&running, // 12
&sz // 13
);
std::cout << "Running: " << running << std::endl;
return 0;
do { // 5
// std::cout << "Loop." << std::endl;
CFRunLoopRunInMode ( // 6
kCFRunLoopDefaultMode, // 7
0.25, // 8
false // 9
);
} while (aqData.mIsRunning);
CFRunLoopRunInMode ( // 10
kCFRunLoopDefaultMode,
1,
//.........这里部分代码省略.........
示例5: downloadOrViewImage
void ChatImageItem::downloadOrViewImage()
{
if (retryButton)
{
message.status = FMessage::Uploading;
retryButton = false;
setButton();
emit mediaUpload(message);
} else if (message.media_wa_type == FMessage::Location)
{
QString url = (message.media_url.isEmpty())
? URL_LOCATION_SHARING +
QString::number(message.latitude) + "," +
QString::number(message.longitude) + "+(" +
message.notify_name.replace("<","<").replace(">",">") + ")"
: message.media_url;
QDesktopServices::openUrl(QUrl(url));
}
else if (!message.local_file_uri.isEmpty())
{
QString uri = "file://" + message.local_file_uri;
QDBusConnection dbus = QDBusConnection::sessionBus();
switch (message.media_wa_type)
{
case FMessage::Audio:
if (message.live)
{
AudioPlayer *player = new AudioPlayer(this);
connect(player,SIGNAL(progress(int)),this,SLOT(updateTime(int)));
connect(player,SIGNAL(finished()),this,SLOT(finishedAudioPlay()));
ui->viewImageButton->setEnabled(false);
player->play(uri);
// We need to notificate the sender that we played the audio
emit voiceNotePlayed(message);
break;
}
case FMessage::Video:
{
DBusNokiaMediaPlayerIf *mediaPlayerBus =
new DBusNokiaMediaPlayerIf(NOKIA_MEDIAPLAYER_DBUS_NAME,
NOKIA_MEDIAPLAYER_DBUS_PATH,
dbus,this);
mediaPlayerBus->mime_open(uri);
}
break;
case FMessage::Image:
{
// The following is to avoid an Image Viewer bug where files without
// EXIF data can't be opened.
QImageReader image(message.local_file_uri);
if (image.format() == "jpeg")
{
ExifData *ed = exif_data_new_from_file(message.local_file_uri.toUtf8().constData());
if (!ed)
{
ed = exif_data_new();
if (ed)
{
Utilities::logData("Creating default Exif data.");
ExifEntry *entry = exif_entry_new();
exif_content_add_entry(ed->ifd[EXIF_IFD_0], entry);
exif_entry_initialize(entry, EXIF_TAG_IMAGE_DESCRIPTION);
entry->data = (unsigned char *) YAPPARI_APPLICATION_NAME;
JPEGData *jpeg = jpeg_data_new_from_file(message.local_file_uri.toUtf8().constData());
jpeg_data_set_exif_data(jpeg, ed);
jpeg_data_save_file(jpeg, message.local_file_uri.toUtf8().constData());
jpeg_data_unref(jpeg);
}
}
if (ed)
exif_data_unref(ed);
}
DBusNokiaImageViewerIf *imageViewerBus =
new DBusNokiaImageViewerIf(NOKIA_IMAGEVIEWER_DBUS_NAME,
NOKIA_IMAGEVIEWER_DBUS_PATH,
dbus,this);
imageViewerBus->mime_open(uri);
//.........这里部分代码省略.........