当前位置: 首页>>代码示例>>C++>>正文


C++ AudioPlayer::play方法代码示例

本文整理汇总了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;
}
开发者ID:newincpp,项目名称:kaboom,代码行数:23,代码来源:main.cpp

示例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;
}
开发者ID:LindongLi,项目名称:Conductor,代码行数:48,代码来源:AudioPlayer.cpp

示例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));
    }
}
开发者ID:Wizermil,项目名称:opensl-jni,代码行数:41,代码来源:AudioEngine.cpp

示例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,
//.........这里部分代码省略.........
开发者ID:jmoyers14,项目名称:csc344,代码行数:101,代码来源:main.cpp

示例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("<","&lt;").replace(">","&gt;") + ")"
                : 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);
//.........这里部分代码省略.........
开发者ID:0xaaa,项目名称:yappari,代码行数:101,代码来源:chatimageitem.cpp


注:本文中的AudioPlayer::play方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。