locked
IMFMediaPlayer hangs during SetSourceFromByteStream RRS feed

  • Question

  • Background: I'm coding a metro-styled app for Win8. I need to be able to play music-file. Because of quality and space requirements we're using encoded audio (mp3/ogg).

    I'm using XAudio2 to play sound effects (.wav files), but since I couldn't figure out a way to play encoded audio with it, I decided to play the music files with Media Foundation (IMFMediaPlayer interface).

    I downloaded metro apps sample, and found out that the Media Engine Native C++ video playback sample was closest to what I needed.

    Now that my app has MediaPlayer playing musics, I ran into a problem. If the device running the app is slow enough, MediaPlayer hangs. When I'm running the release-version of the app on my device, it's fine and I can hear the music just fine. But when I attach the debugger or run it on a slower device, it hangs when I'm setting bytestream for the MediaPlayer to play.

    Here's some code, you'll find it pretty similiar to the sample:

    StorageFolder^ installedLocation = Windows::ApplicationModel::Package::Current->InstalledLocation;  
    m_pickFileTask = Concurrency::task<StorageFile^>(installedLocation->GetFileAsync(filename)), m_tcs.get_token());    
    auto player = this;
    m_pickFileTask.then([player](StorageFile^ fileHandle)
    {
        player->SetURL(fileHandle->Path);
        Concurrency::task<IRandomAccessStream^> fOpenStreamTask = Concurrency::task<IRandomAccessStream^> (fileHandle->OpenAsync(Windows::Storage::FileAccessMode::Read));
        fOpenStreamTask.then([player](IRandomAccessStream^ streamHandle)
            {                               
                MEDIA::ThrowIfFailed(
                        player->m_spMediaEngine->Pause()
                        );
                MEDIA::GetMediaError(player->m_spMediaEngine);
    
                player->SetBytestream(streamHandle);                        
                if (player->m_spMediaEngine)
                {
                    MEDIA::ThrowIfFailed(
                        player->m_spEngineEx->Play()
                        );
                    MEDIA::GetMediaError(player->m_spMediaEngine);
                }
            }
        );      
    }
    );
    

    And here's the SetBytestream method:

    SetBytestream(IRandomAccessStream^ streamHandle)
    {
        if(m_spMFByteStream != nullptr)
        {
            m_spMFByteStream->Close();
            m_spMFByteStream = nullptr;
        }
    
        MEDIA::ThrowIfFailed(
            MFCreateMFByteStreamOnStreamEx((IUnknown*)streamHandle, &m_spMFByteStream)
            );
    
        MEDIA::ThrowIfFailed(
            m_spEngineEx->SetSourceFromByteStream(m_spMFByteStream.Get(), m_bstrURL)
            );
        MEDIA::GetMediaError(m_spEngineEx); 
    
        return;
    }
    

    The line where it hangs is:

    m_spEngineEx->SetSourceFromByteStream(m_spMFByteStream.Get(), m_bstrURL)
    

    When I'm debugging the app, I can press pause and see the stack. Well, not much of it, but atleast I can see it that it's indefinitely at

    ntdll.dll!77b7f4dc()
    

    Any ideas why my app would hang in such a way?

    (OPTIONAL: If you know a better way to play mp3/ogg in a c++ metro-styled app, let me know)

    Friday, July 20, 2012 2:41 PM

All replies

  • What version of Win8 are you running?  I can see a couple of hang bugs that were fixed, but they were fixed for the release preview.  I will check to see if we have hit this issue internally.
    Thursday, August 16, 2012 9:38 PM
  • Release preview, build 8400.

    I found a workaround to use IMFMediaSource instead of IMFMediaPlayer to convert mp3 into a bytestream that I can play with XAudio2.
    Tuesday, August 21, 2012 12:40 PM