none
Playing MP3 Audio Files (And Not Using WMP!) RRS feed

  • General discussion

  • Based on a thread earlier today, and in particular an answer that Cor gave wherein he pointed to this article, I thought that I'd do some investigation. Many times here the question has come up about playing .mp3 audio files and NOT using the Windows Media Player object. In the article referenced above, he shows how this can be done via DirectX.

    I've looked at DirectX before and it seemed ambiguous so I never really dug into it but it turns out to be pretty simple actually! I thought that I'd write this as a step-by-step of what I did so that maybe some of you will find use from it.

    The whole thing stems around using DirectX and to begin with, you'll need to download and install the SDK for it. If you haven't already, try this link. Do be aware that it's a large download (about a half gig)! Once that's installed, create a form and add a reference to the class that we need for this. You can do this several ways, but the way I usually do is to right-click on the name in the Solution Explorer, then choose "Add Reference":

     

     

    Now look for the class that we need (Microsoft.DirectX.AudioVideoPlayback) as shown here:

     

     

    Be sure that you use an Imports statement just above your "Class" in the form and refer to that newly imported DirectX class:

     

     

    So that you have an idea of how I set my form up (horrible design but it was just a test!):

     

     

    Then lastly add a timer in so that we'll have a way to show the audio file's current position (in seconds) as it's playing:

     

     

    I've decided to put the code in my own .htm file and you can see it all here. Some screenshots of the finished version:

     

     

     

     

     


    Some final comments and questions, actually:

    First, I get a message in debug mode telling me that it will not continue due to a "Loader Lock". I looked through the forum messages and I see where a few years ago, NoBugz replied to someone that it will only happen in debug mode and it appears to be the case - it runs fine ONCE BUILT but it won't run at all in debug. Can anyone tell me what the heck it is and if there's a way around it?

    Secondly, I'm not fond of using at timer that 'ticks' once per second. That seems like it's a waste of processing to me, but I couldn't figure out any other way to effectively refresh the label which shows the current position (in seconds). Does anyone have any thoughts there?

     


    I hope that some of you find this useful and if you decide to embellish it, I hope you'll add to this thread so that everyone can benefit from it.

    :)

    Monday, September 27, 2010 12:20 AM

All replies

  • I use the express version . In the express version to disable the LoaderLock exception in debug choose exceptions on the debug menu . In the dialog that opens expand Managed Debugging Assistants find LoaderLock and change the checkbox option(s) .
    Coding4fun Be a good forum member mark posts that contain the answers to your questions or those that are helpful
    Please format the code in your posts with the button . Makes it easier to read . Or use the Forum Code Formatter by JohnWein http://social.msdn.microsoft.com/Forums/en-US/vbgeneral/thread/bf977a14-d9d4-4e84-9784-bf76b9e23261
    Monday, September 27, 2010 12:35 AM
  • I use the express version . In the express version to disable the LoaderLock exception in debug choose exceptions on the debug menu . In the dialog that opens expand Managed Debugging Assistants find LoaderLock and change the checkbox option(s) .
    Coding4fun Be a good forum member mark posts that contain the answers to your questions or those that are helpful
    Please format the code in your posts with the button . Makes it easier to read . Or use the Forum Code Formatter by JohnWein http://social.msdn.microsoft.com/Forums/en-US/vbgeneral/thread/bf977a14-d9d4-4e84-9784-bf76b9e23261


    Great! Thanks BDB, but what the heck is a "LoaderLock"?

    Is it related to Goldilocks? Are bears involved with this at all? :-]

    Monday, September 27, 2010 12:44 AM
  • http://msdn.microsoft.com/en-us/library/ms172219.aspx

    The loaderLock managed debugging assistant (MDA) detects attempts to execute managed code on a thread that holds the Microsoft Windows operating system loader lock. Any such execution is illegal because it can lead to deadlocks and to use of DLLs before they have been initialized by the operating system's loader.


    Coding4fun Be a good forum member mark posts that contain the answers to your questions or those that are helpful
    Please format the code in your posts with the button . Makes it easier to read . Or use the Forum Code Formatter by JohnWein http://social.msdn.microsoft.com/Forums/en-US/vbgeneral/thread/bf977a14-d9d4-4e84-9784-bf76b9e23261
    Monday, September 27, 2010 12:53 AM
  • http://msdn.microsoft.com/en-us/library/ms172219.aspx

    The loaderLock managed debugging assistant (MDA) detects attempts to execute managed code on a thread that holds the Microsoft Windows operating system loader lock. Any such execution is illegal because it can lead to deadlocks and to use of DLLs before they have been initialized by the operating system's loader.


    Coding4fun Be a good forum member mark posts that contain the answers to your questions or those that are helpful
    Please format the code in your posts with the button . Makes it easier to read . Or use the Forum Code Formatter by JohnWein http://social.msdn.microsoft.com/Forums/en-US/vbgeneral/thread/bf977a14-d9d4-4e84-9784-bf76b9e23261


    Thanks - I read that earlier and am only more confused though. If it's managed code, what's the problem?

    Anyway, thanks for the assistance as always. :)

    Monday, September 27, 2010 12:57 AM
  • I have never had a problem with unchecking the LoaderLock so I can't say if it is a good thing or not .
    Coding4fun Be a good forum member mark posts that contain the answers to your questions or those that are helpful
    Please format the code in your posts with the button . Makes it easier to read . Or use the Forum Code Formatter by JohnWein http://social.msdn.microsoft.com/Forums/en-US/vbgeneral/thread/bf977a14-d9d4-4e84-9784-bf76b9e23261
    Monday, September 27, 2010 12:58 AM
  • I have never had a problem with unchecking the LoaderLock so I can't say if it is a good thing or not .
    Coding4fun Be a good forum member mark posts that contain the answers to your questions or those that are helpful
    Please format the code in your posts with the button . Makes it easier to read . Or use the Forum Code Formatter by JohnWein http://social.msdn.microsoft.com/Forums/en-US/vbgeneral/thread/bf977a14-d9d4-4e84-9784-bf76b9e23261

    Thanks again. :)
    Monday, September 27, 2010 1:39 PM
  • Frank,

    I don't do anything today anymore, I think I can say thanks from the community for figuring this out.

     


    Success
    Cor
    Monday, September 27, 2010 3:51 PM
  • Frank,

    I don't do anything today anymore, I think I can say thanks from the community for figuring this out.

     


    Success
    Cor


    Thanks Cor :)

    ... and thanks for finding that article. That opened the door. :)

    Monday, September 27, 2010 4:01 PM
  • As an adjunct to this thread, in order to deploy your application, you'll also need to include the base class (Microsoft.DirectX) along with your application.

    You can do this manually of course, but I find it easier to have everything in one place - the \bin\Release folder. To do this, add a new reference the same as was shown above and add "Microsoft.DirectX" to your application. Next, right-click on the name in the Solution Explorer and click on "Properties", then click the "References" tab from there:

     

     

    You'll notice that by default, the "Copy To Local" is set to false. Select both of them as shown above, then in the properties for them (normally at the lower-right of that page), change those to true:

     

     

    When you rebuild your application, those two dll's will be in your \bin\Release folder, ready for you to build your deployment by whatever means you do that.

    Sunday, October 3, 2010 7:59 PM