locked
Capture media in background RRS feed

  • Question

  • Is there a way to keep recording audio or video when the user switches to another app? It seems that currently MediaCapture immediately stops as soon as the app is hidden
    Wednesday, August 29, 2012 7:42 PM

Answers

All replies

  • Hello,

    If you are writing a communications app such as VO/IP, etc. we do have low level hooks to allow you to continue to run in the background. Since background tasks can drain the battery rather quickly I would recommend that you avoid doing this if possible.

    Here is a link to a sample that should show you all you need to do:

    http://code.msdn.microsoft.com/windowsapps/Audio-hardware-offload-280dc923

    Thanks,

    James


    Windows Media SDK Technologies - Microsoft Developer Services - http://blogs.msdn.com/mediasdkstuff/

    Wednesday, August 29, 2012 9:09 PM
    Moderator
  • James,

    Thank you for the advice. The link is broken however, can you please check it?

    Do I need to use WASAPI or is there something lower still?

    I'm working on an audio recorder app for which it makes sense to keep recording in background, as the user may switch to other apps while they dictate or take notes.

    Wednesday, August 29, 2012 10:39 PM
  • Hello,

    Q. The link is broken however, can you please check it?
    A. It looks like we pulled that sample for RTM. Let me check with the architects and see if we have a replacement for RTM. If you don't hear from me by the end of next week please bump this post.

    Q. Do I need to use WASAPI or is there something lower still?
    A. WASAPI is as low as you can go.

    Thanks,

    James


    Windows Media SDK Technologies - Microsoft Developer Services - http://blogs.msdn.com/mediasdkstuff/

    Friday, August 31, 2012 11:48 PM
    Moderator
  • James,

    Thank you for the reply.

    So using WASAPI can enable background audio capture? In the absence of sample what are the functions/flags/settings that I should start looking at to make this happen.

    Saturday, September 1, 2012 2:10 PM
  • Unfortunately I haven't heard anything back from the architects. My immediate reaction is that they don't want people doing this but I will let you know if I do eventually hear back from them.

    -James


    Windows Media SDK Technologies - Microsoft Developer Services - http://blogs.msdn.com/mediasdkstuff/

    Tuesday, September 11, 2012 12:20 AM
    Moderator
  • James,

    Thank you for keeping me up to date. Please let me know if solution is found. Although I initially posted this in HTML5 forum I don't mind doing C++ coding to make this scenario work.

    It would be strange if Modern UI apps would be completely banned from capturing audio in background. I assume that Modern UI version of Skype once it is released would want to do the very same thing.

    Tuesday, September 11, 2012 6:37 PM
  • Please take a look at this sample. It should answer your questions.

    Windows Audio Session (WASAPI) sample

    http://code.msdn.microsoft.com/windowsapps/Windows-Audio-Session-22dcab6b

    -James


    Windows Media SDK Technologies - Microsoft Developer Services - http://blogs.msdn.com/mediasdkstuff/

    Tuesday, September 18, 2012 12:42 AM
    Moderator
  • James,

    I've tried running this sample and just records silence when the app is in background... Am I missing something?

    Thursday, September 20, 2012 7:50 PM
  • In the Windows Audio Session (WASAPI) sample link given by james need some upgrade & it should work in windows 8.1

    use :

    Windows::Media::Devices::AudioDeviceRole::Communications in below case.

    MediaDevice::GetDefaultAudioCaptureId( Windows::Media::Devices::AudioDeviceRole::Default );

    MediaDevice::GetDefaultAudioRenderId( Windows::Media::Devices::AudioDeviceRole::Default ); 


    Monday, December 9, 2013 3:20 AM
  • Does anyone know what API being used in this sample will keep the media capture alive? I started to go spelunking in the source code but there's a lot there and thought I'd just ask in case someone else already managed to figure it out. Thanks, Tim

    Wednesday, July 2, 2014 7:25 PM
  • Hello Tim,

    Take a look at:

    AudioClientProperties

    http://msdn.microsoft.com/en-us/library/windows/desktop/hh968105(v=vs.85).aspx

    AUDIO_STREAM_CATEGORY

    http://msdn.microsoft.com/en-us/library/windows/desktop/hh404178(v=vs.85).aspx

    IAudioClient2::SetClientProperties

    http://msdn.microsoft.com/en-us/library/windows/desktop/hh968106(v=vs.85).aspx

    I hope this helps,

    James


    Windows SDK Technologies - Microsoft Developer Services - http://blogs.msdn.com/mediasdkstuff/

    Wednesday, July 2, 2014 11:34 PM
    Moderator