Is it possible to get audio (left/right) sound levels of MediaPlayer?


Toutes les réponses

  • Hi,

      >> Is it possible to get audio (left/right) sound levels of MediaPlayer?

    I would like to know what you want is to get the volume or not. If you want to get the volume, please take a look at the Volume property:

    Best Regards,

    Ming Xu.

    Please mark the replies as answers if they help or unmark if not.
    If you have any feedback about my replies, please contact
    Microsoft One Code Framework

    lundi 14 mai 2012 09:47
  • Volume property defines maximum level. I want to get instant levels according to the sound that's currently being played.

    I want to get these levels as i think they are already being calculated inside of MediaPlayer.

    (I want to draw left and right audio levels to make an animated audio bar for each channel of audio. I do not need real FFT data to draw frequencies. I know it requires custom decoding so i am staying away from it. I just want 2 already calculated values from MediaPlayer (Left + Right levels in dB or any converted measurement)

    lundi 14 mai 2012 09:57
  • Hi,

    I’m not aware of a solution to retrieve these levels using MediaPlayer. From my experience, MediaPlayer is a MediaElement with some default playback controls. It does not stand by low level audio operations. Please try to use a lower level API, such as Core Audio APIs, if you want to obtain more details.

    Best Regards,

    Ming Xu.

    Please mark the replies as answers if they help or unmark if not.
    If you have any feedback about my replies, please contact
    Microsoft One Code Framework

    mardi 15 mai 2012 10:53
  • That would be very good if MediaElement had "VolumeMonitoring" extension.. I don't think that we have to be left alone to implement everything in lower level to do such a basic thing.

    Using lower-level requires us to make the decoding manually. It's an overkill for a basic volume monitoring operation. I would love to have this feature in the near future.

    mardi 15 mai 2012 11:17
  • Hello ElRaymond,

    I would like to follow up with you on your feature request. If we did add volume level monitoring to a basic control like the MediaElement how would you like to get this information? Would you prefer an event or would you prefer to poll? How often would you like the level monitoring information to be updated? At the audio sample rate or something more manageable like every 200ms? What algorithms would you prefer to use us use to return the audio level information? Would you prefer linear, RMS or DB?

    You likely don't need to drop all the way down to the core audio APIs to solve this problem. Personally I would write an MFT that just plugged into the MediaElement and returned the volume level information to my app. While you still have to write C++ its much easier than coding to WASAPI.

    If you are interested in writing an MFT let me know and I can post some pointers.

    I hope this helps,


    Windows Media SDK Technologies - Microsoft Developer Services -

    jeudi 17 mai 2012 01:11
  • Thank you for your concern & reply.

    Here is how it could be useful for me:

    public MediaElement(MediaPlayer) myPlayer;
    public void startMP() {
    myPlayer= new MediaElement/MediaPlayer();
    // or set it from xaml
    mPlayer.IsMeteringEnabled=true; //enable volume monitoring
    // set Source and start mPlayer here...
    DispatcherTimer timer = new DispatcherTimer();
    timer.Interval = TimeSpan.FromMilliseconds(100);
    timer.Tick += redrawLevels;
    public double filterValue(double value){
    } else if(value>0){
    return value;
    private void redrawLevels(object sender, object e){
    myPlayer.updateMeters(); //without this, values will be same with the previous call to LastMeteredLevel()
    MeteredLevel channelLevels = myPlayer.LastMeteredLevel();
    double leftPower= filterValue(channelLevels.peakPowerOf(MediaChannel.LeftChannel));
    double leftPowerLevel= Math.Pow(10,0.05 * leftPower);
    float levelRectangleWidth=300* leftPowerLevel; // width will be between 0 and 300;

    So, i can update calculations when i need it and windows may internally ignore or accept the speed of updating. I think it can handle far far more than 0.1 seconds, but for example, 0.1 is enough for this example.

    Eventhough that would be the best to have this feature with MediaPlayer, would you please share more about what you said with MFT? I really have no experience related to that (but i know c++ and i also have used another c++ library in my same c# project). Please write the reply of this sentence seperate from the above example as i also want to see the result of this feature request.

    • Modifié ELRaymod jeudi 17 mai 2012 05:12 typo
    jeudi 17 mai 2012 05:09
  • ElRaymond,

    So you would like to poll the value and are only interested in the last peak value. I find this fascinating.  This is certainly not the way I would like to see this problem solved. But that is just my opinion. There are a number of ways to solve the problem. That said, we will likely not see a "meter" feature in the MediaElement anytime soon. I'll run it by the team but due to the enormous amount of "chatter" that either polling or receiving via an event would cause, my guess is that performance would not be acceptable on low power devices. Keep in mind that every time you cross between native, WinRT and managed you incur overhead that can carry with it overhead that can cause unexpectedly high CPU usage.

    AFA creating your own MFT, the "greyscale" MFT in the following sample is a great place to start:

    Media capture using webcam sample



    Windows Media SDK Technologies - Microsoft Developer Services -

    vendredi 18 mai 2012 00:33
  • I am interested in the average power where i get a value in db. getting the peak value would be another function so i can draw more things on the screen.

    This is how i use this on some other platforms and i would love to use it similarly in Windows too. I am not insisting on the way i've written. The best way that Windows (mediaplayer) can handle it on mobile or desktop will be O.K. for me.

    I've looked into the sample you've given. As i understand after coding the C++ part, i have to add it to the mediaplayer object with AddAudioEffect. Now i have to find the way to get only volume levels without decoding making FFTs etc… (:

    • Modifié ELRaymod vendredi 18 mai 2012 05:12 typo
    vendredi 18 mai 2012 05:11