Results 1 to 17 of 17

Thread: [RESOLVED] Play .wav from .res with Windows Media Player control...

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Sep 2013
    Posts
    190

    Resolved [RESOLVED] Play .wav from .res with Windows Media Player control...

    ...without extracting it and creating a new file to play from. Ideas on how to achieve this?

  2. #2
    Default Member Bonnie West's Avatar
    Join Date
    Jun 2012
    Location
    InIDE
    Posts
    4,060

    Re: Play .wav from .res with Windows Media Player control...

    Use the Res: protocol for this. Example:

    Code:
    WindowsMediaPlayer1.URL = "res://" & App.EXEName & ".exe/WAVE/1"
    See INFO: Syntax of the Res: Protocol and Some Known Related Issues.
    On Local Error Resume Next: If Not Empty Is Nothing Then Do While Null: ReDim i(True To False) As Currency: Loop: Else Debug.Assert CCur(CLng(CInt(CBool(False Imp True Xor False Eqv True)))): Stop: On Local Error GoTo 0
    Declare Sub CrashVB Lib "msvbvm60" (Optional DontPassMe As Any)

  3. #3

    Thread Starter
    Addicted Member
    Join Date
    Sep 2013
    Posts
    190

    Re: Play .wav from .res with Windows Media Player control...

    That doesn't seem to work. I created the .rc file with theSound as my id, and then created the .RES file. I called it, as your example states to, replacing the "/1" with "/theSound", yet it does not work. It doesn't even provide an error. I tried several different sound ID's, but to no avail. I'm using Windows 7.

  4. #4
    PowerPoster
    Join Date
    Jan 2008
    Posts
    11,074

    Re: Play .wav from .res with Windows Media Player control...

    This works for me

    Code:
     MediaPlayer1.Stop
     MediaPlayer1.FileName = "res://" & App.Path & "\" & App.EXEName & ".exe/CUSTOM/#101"


    Anything I post is an example only and is not intended to be the only solution, the total solution nor the final solution to your request nor do I claim that it is. If you find it useful then it is entirely up to you to make whatever changes necessary you feel are adequate for your purposes.

  5. #5
    PowerPoster
    Join Date
    Jan 2008
    Posts
    11,074

    Re: Play .wav from .res with Windows Media Player control...

    BTW: The example I posted is for the older style WMP.

    If you can't get the URL to work for the newer WMP (as Bonnie posted) you probably will have to first convert the res data to a byte array and then save it to a file then set the URL to that file
    Last edited by jmsrickland; Jul 17th, 2015 at 03:12 PM.


    Anything I post is an example only and is not intended to be the only solution, the total solution nor the final solution to your request nor do I claim that it is. If you find it useful then it is entirely up to you to make whatever changes necessary you feel are adequate for your purposes.

  6. #6
    VB-aholic & Lovin' It LaVolpe's Avatar
    Join Date
    Oct 2007
    Location
    Beside Waldo
    Posts
    19,541

    Re: Play .wav from .res with Windows Media Player control...

    Just FYI: The app has to be compiled to use the "res" protocol, correct? Not my area of expertise, but App.ExeName doesn't really exist until the app is compiled. Not sure whether OP is using on compiled copy or not.
    Insomnia is just a byproduct of, "It can't be done"

    Classics Enthusiast? Here's my 1969 Mustang Mach I Fastback. Her sister '67 Coupe has been adopted

    Newbie? Novice? Bored? Spend a few minutes browsing the FAQ section of the forum.
    Read the HitchHiker's Guide to Getting Help on the Forums.
    Here is the list of TAGs you can use to format your posts
    Here are VB6 Help Files online


    {Alpha Image Control} {Memory Leak FAQ} {Unicode Open/Save Dialog} {Resource Image Viewer/Extractor}
    {VB and DPI Tutorial} {Manifest Creator} {UserControl Button Template} {stdPicture Render Usage}

  7. #7
    PowerPoster
    Join Date
    Jan 2008
    Posts
    11,074

    Re: Play .wav from .res with Windows Media Player control...

    You can run from IDE as long as there is a Compiled copy in the folder but that is not the problem. I have only been able to get it to work from a disk file.
    Last edited by jmsrickland; Jul 17th, 2015 at 03:01 PM.


    Anything I post is an example only and is not intended to be the only solution, the total solution nor the final solution to your request nor do I claim that it is. If you find it useful then it is entirely up to you to make whatever changes necessary you feel are adequate for your purposes.

  8. #8

    Thread Starter
    Addicted Member
    Join Date
    Sep 2013
    Posts
    190

    Re: Play .wav from .res with Windows Media Player control...

    LaVolpe: I tested your theory and it does not seem to matter whether it is compiled or not.

    jms: I tried your code and it doesn't seem to work, either. Also, I'd really rather not convert it to a file and then save it to disk. Doing so would defeat the purpose of using the .res file.

  9. #9
    PowerPoster
    Join Date
    Jan 2008
    Posts
    11,074

    Re: Play .wav from .res with Windows Media Player control...

    My method works its just you need to use earlier version of WMP


    Anything I post is an example only and is not intended to be the only solution, the total solution nor the final solution to your request nor do I claim that it is. If you find it useful then it is entirely up to you to make whatever changes necessary you feel are adequate for your purposes.

  10. #10

    Thread Starter
    Addicted Member
    Join Date
    Sep 2013
    Posts
    190

    Re: Play .wav from .res with Windows Media Player control...

    True, but I would like it to work with a more "modern" version, as in what most users have now.

  11. #11
    VB-aholic & Lovin' It LaVolpe's Avatar
    Join Date
    Oct 2007
    Location
    Beside Waldo
    Posts
    19,541

    Re: Play .wav from .res with Windows Media Player control...

    Maybe you can show us exactly the line you used to try to run it from the res file?

    In the mean time, if you can find a way to play a file by a byte array, you can always use LoadResData() to return a byte array. And as a last resort, write the byte array to a file & pass the path/file name to WMP
    Insomnia is just a byproduct of, "It can't be done"

    Classics Enthusiast? Here's my 1969 Mustang Mach I Fastback. Her sister '67 Coupe has been adopted

    Newbie? Novice? Bored? Spend a few minutes browsing the FAQ section of the forum.
    Read the HitchHiker's Guide to Getting Help on the Forums.
    Here is the list of TAGs you can use to format your posts
    Here are VB6 Help Files online


    {Alpha Image Control} {Memory Leak FAQ} {Unicode Open/Save Dialog} {Resource Image Viewer/Extractor}
    {VB and DPI Tutorial} {Manifest Creator} {UserControl Button Template} {stdPicture Render Usage}

  12. #12

    Thread Starter
    Addicted Member
    Join Date
    Sep 2013
    Posts
    190

    Re: Play .wav from .res with Windows Media Player control...

    Code:
    WindowsMediaPlayer1.URL = "res://" & App.Path & "\" & App.EXEName & ".exe/CUSTOM/theSound"
    WindowsMediaPlayer1.Controls.play
    I've also used it without adding the "App.Path" part and used "WAVE" instead of "CUSTOM". No difference.

    And if I'm going to write the information to a file (which I'm trying to stay away from), I mind as well just use the .wav files instead of combining them into a .res file.

  13. #13
    PowerPoster
    Join Date
    Jan 2008
    Posts
    11,074

    Re: Play .wav from .res with Windows Media Player control...

    The path in the "..../CUSTOM/theSound" part has to match the actual res name and number assigned to it. Are you doing that?

    Do you have to use Windows Media Player? You can play from the res file using other means which I have apps that do that

    MediaPlayer1.FileName = "res://" & App.Path & "\" & App.EXEName & ".exe/CUSTOM/#101"
    Attached Images Attached Images  
    Last edited by jmsrickland; Jul 17th, 2015 at 07:17 PM.


    Anything I post is an example only and is not intended to be the only solution, the total solution nor the final solution to your request nor do I claim that it is. If you find it useful then it is entirely up to you to make whatever changes necessary you feel are adequate for your purposes.

  14. #14

    Thread Starter
    Addicted Member
    Join Date
    Sep 2013
    Posts
    190

    Re: Play .wav from .res with Windows Media Player control...

    Yes, it matches exactly. I would think it would cause a path/file error if not. And yes, I would really like to use WMP. If this is not possible, (which it is beginning to seem, as I can't find an answer anywhere) I will probably just go ahead and include the actual .wav files and just call it from WMP that way. I hate to do that, but oh well.

  15. #15

    Thread Starter
    Addicted Member
    Join Date
    Sep 2013
    Posts
    190

    Re: Play .wav from .res with Windows Media Player control...

    Okay. It worked. I used the

    Code:
    WindowsMediaPlayer1.URL = "res://" & App.EXEName & ".exe/WAVE/theSound"
    as before, but this time it worked. And it DOES need to be compiled before it will work. I'm really not sure why it worked this time and not before. Very strange. Anyway, thank you all.

  16. #16
    PowerPoster
    Join Date
    Jan 2008
    Posts
    11,074

    Re: [RESOLVED] Play .wav from .res with Windows Media Player control...

    It won't cause a path/file error; it just won't play
    Last edited by jmsrickland; Jul 17th, 2015 at 09:36 PM.


    Anything I post is an example only and is not intended to be the only solution, the total solution nor the final solution to your request nor do I claim that it is. If you find it useful then it is entirely up to you to make whatever changes necessary you feel are adequate for your purposes.

  17. #17
    PowerPoster
    Join Date
    Jan 2008
    Posts
    11,074

    Re: Play .wav from .res with Windows Media Player control...

    Quote Originally Posted by Conroy Vanderbluff View Post
    Okay. It worked. I used the

    Code:
    WindowsMediaPlayer1.URL = "res://" & App.EXEName & ".exe/WAVE/theSound"
    as before, but this time it worked. And it DOES need to be compiled before it will work. I'm really not sure why it worked this time and not before. Very strange. Anyway, thank you all.
    Good, happy it works for you but still I cannot get .URL to read res data to work for me and I am using newer version of WMP or my version is still not the latest. I'm using wmp.dll version 9.0.0.4503


    Anything I post is an example only and is not intended to be the only solution, the total solution nor the final solution to your request nor do I claim that it is. If you find it useful then it is entirely up to you to make whatever changes necessary you feel are adequate for your purposes.

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width