Results 1 to 19 of 19

Thread: [RESOLVED] Play audio files

  1. #1

    Thread Starter
    PowerPoster
    Join Date
    Feb 2017
    Posts
    5,064

    Resolved [RESOLVED] Play audio files

    Hello, I have to decide something and I would like to have some advice from other more experienced developers on the subject.

    To provide some context: in my program the user performs a search, that in some cases the result points that there is an audio related to the result.
    Currently the program only tells to the user that there is an audio (and which one is), and in the case the user has the audio (it's not always the case) he needs to go, locate and play the audio by himself, if he wants.

    The audios are usually organized in one main folder where each one is in a different sub-folder, and may consist on one mp3 file or more than one mp3 file each "audio".

    I had a request for an user that he wants to be able to play the audio clicking in the results directly, of course first configuring the main folder where all the audios are.

    I have several options:

    1) No to do anything.
    2) To open the folder where the audio file(s) is (or are) and let the user play them with whatever program he wants.
    3) To play the files with the default program that is configured in Windows for playing mp3 (how to add more than one file, is there an standard protocol?).
    4) To let the user configure with what program he wants to play them (also how to add more than one file, is there an standard protocol?)
    5) To make my own audio player whithin the program.

    I'm thinking that perhaps the best option is 2)

    To play the files directly would be a nice feature, but I don't want problems. I don't know how each Windows is configured (or misconfigured).
    I think I can rely in that Windows Media Player will be always available, but perhaps some will want to use another player...

    Option 5) would avoid problems, but I think it's too much work for adding this "feature".

    Opinions?

    PS: I cannot go to the users houses to solve problems, many of them are far away.

    Thanks in advance.

  2. #2
    PowerPoster
    Join Date
    Feb 2006
    Posts
    24,482

    Re: Play audio files

    Well, maybe this will give you an idea:

    Code:
    Option Explicit
    
    Private Const ssfDESKTOP = 0
    Private Const ssfMYMUSIC = &HD& 'May not be valid until Windows Vista.
    
    Private Shell As Object
    
    Private Sub Dir1_Change()
        File1.Path = Dir1.Path
    End Sub
    
    Private Sub Drive1_Change()
        Dir1.Path = Drive1.Drive
    End Sub
    
    Private Sub File1_DblClick()
        On Error Resume Next
        With File1
            Shell.NameSpace(ssfDESKTOP).ParseName(.Path & "\" & .FileName).InvokeVerb "openas"
        End With
    End Sub
    
    Private Sub Form_Load()
        'FileListBox is always IntegralHeight = True, so size the Form to fit the
        'height of our controls:
        Height = (Height - ScaleHeight) + (Drive1.Height + Dir1.Height + File1.Height)
    
        Set Shell = CreateObject("Shell.Application")
        With Shell.NameSpace(ssfMYMUSIC).Self
            Drive1.Drive = .Path
            Dir1.Path = .Path
        End With
    End Sub
    Name:  sshot.png
Views: 672
Size:  5.8 KB

    Double-click the tune to raise the
    Shell "Open with" dialog
    Attached Files Attached Files

  3. #3

    Thread Starter
    PowerPoster
    Join Date
    Feb 2017
    Posts
    5,064

    Re: Play audio files

    Hello dilettante.
    Thank you!

    Beyond the code, does it means that your opinion for best is option 4)?

    But forget about the code for now, I am just asking for opinions about pros and cons of the options in order to decide what it's best to do.

    I'm not asking for code to do it (any of the options, at least for now), but what problems may I encounter with each one, and what would be best to avoid them.

    Thanks anyway for your example code, it could be really useful at the end if I decide to go for option 4).

  4. #4
    PowerPoster
    Join Date
    Feb 2006
    Posts
    24,482

    Re: Play audio files

    Well you could give them the choice between 3 and 4, using the "open" verb to open in the default configured tool.

    The whole thing sounds a little dicey though, and making yet another music player seems pointless. There just isn't anything all that great about duplicating software already on the system.

  5. #5

    Thread Starter
    PowerPoster
    Join Date
    Feb 2017
    Posts
    5,064

    Re: Play audio files

    Quote Originally Posted by dilettante View Post
    Well you could give them the choice between 3 and 4, using the "open" verb to open in the default configured tool.

    The whole thing sounds a little dicey though, and making yet another music player seems pointless. There just isn't anything all that great about duplicating software already on the system.
    What do you mean "dicey"?

    My main goal is not to have problems.
    I don't want this feature to generate support calls.

  6. #6
    PowerPoster
    Join Date
    Jun 2013
    Posts
    7,253

    Re: Play audio files

    There's several ways to play *.mp3 resources directly from a ByteArray (so you could host the MP3-snippets in a DB-BlobField for example) -
    on Vista and higher MS-CoreAudio can be used for example - as demonstrated here:
    http://www.vbforums.com/showthread.p...CoreAudio-Demo

    But DirectX could also be used to load and play MP3-SoundBuffers - as well as
    the good old ICM-APIs, as well as DirectShow (after you build a graph).

    Olaf

  7. #7

    Thread Starter
    PowerPoster
    Join Date
    Feb 2017
    Posts
    5,064

    Re: Play audio files

    Quote Originally Posted by Schmidt View Post
    There's several ways to play *.mp3 resources directly from a ByteArray (so you could host the MP3-snippets in a DB-BlobField for example) -
    on Vista and higher MS-CoreAudio can be used for example - as demonstrated here:
    http://www.vbforums.com/showthread.p...CoreAudio-Demo

    But DirectX could also be used to load and play MP3-SoundBuffers - as well as
    the good old ICM-APIs, as well as DirectShow (after you build a graph).

    Olaf
    Hi Olaf,

    It can be up to 100 GB or more of mp3 files.
    The users already have the mp3 on files, organized in different folders (some of the users do).

    My current idea to avoid possible problems is to go for option 2).
    Not the best for the users, that's why I'm asking this.

  8. #8
    PowerPoster
    Join Date
    Feb 2006
    Posts
    24,482

    Re: Play audio files

    It is hard to do a better job than Windows Desktop Search has since Vista. One of the few tools you can make an argument for might be Copernic Desktop Search but even that has seen its market share dwindle to nearly nothing. Most other serious products have long since abandoned the market. With the Cortana voice agent user interface we have now the bar has been raised just that much higher.

  9. #9
    PowerPoster
    Join Date
    Feb 2006
    Posts
    24,482

    Re: Play audio files

    The "open with" dialog lets the user go ahead and choose the default program, pick from a list of known programs, or specify an arbitrary program.

  10. #10
    PowerPoster
    Join Date
    Jun 2013
    Posts
    7,253

    Re: Play audio files

    Quote Originally Posted by Eduardo- View Post
    It can be up to 100 GB or more of mp3 files.
    The users already have the mp3 on files, organized in different folders (some of the users do).
    Well, if it's from existing (User-)Files, then the easiest (most reliable) way to play them,
    is to use the MS quartz.dll (which works from XP onwards, based on DirectShow-graphs).

    Simply put a reference to: [ActiveMovie Control type library]
    into an empty project, then drag a new File1-FileList-Control onto your Form,
    adapt the Path in the Form_Load and check out the following:

    Code:
    Option Explicit
    
    Private FGM As FilgraphManager
    
    Private Sub Form_Load()
      File1.Path = "E:\MP3"
      File1.Pattern = "*.mp3"
    End Sub
     
    Private Sub File1_Click() 'here a simple FileList is used as a kind of "PlayList", but that can be changed easily to any List-Control
      If Not FGM Is Nothing Then FGM.Stop
      Set FGM = New FilgraphManager
          FGM.RenderFile File1.Path & "\" & File1.FileName
          FGM.Run
    End Sub
    HTH

    Olaf

  11. #11

    Thread Starter
    PowerPoster
    Join Date
    Feb 2017
    Posts
    5,064

    Re: Play audio files

    Quote Originally Posted by dilettante View Post
    The "open with" dialog lets the user go ahead and choose the default program, pick from a list of known programs, or specify an arbitrary program.
    Ok, but that would have to run in a configuration option, because I won't make the user to choose what program he wants every time that he clicks to play a file.

    Besides, there is the other issue, how to handle the case when the audio is split on several files.
    That happens in some cases, that the audio is tracked (divided in several mp3 files).
    How to add all the files to the queue in the player, I wonder if there is an standard for that or each program works differently?

  12. #12

    Thread Starter
    PowerPoster
    Join Date
    Feb 2017
    Posts
    5,064

    Re: Play audio files

    Quote Originally Posted by Schmidt View Post
    Well, if it's from existing (User-)Files, then the easiest (most reliable) way to play them,
    is to use the MS quartz.dll (which works from XP onwards, based on DirectShow-graphs).

    Simply put a reference to: [ActiveMovie Control type library]
    into an empty project, then drag a new File1-FileList-Control onto your Form,
    adapt the Path in the Form_Load and check out the following:

    Code:
    Option Explicit
    
    Private FGM As FilgraphManager
    
    Private Sub Form_Load()
      File1.Path = "E:\MP3"
      File1.Pattern = "*.mp3"
    End Sub
     
    Private Sub File1_Click() 'here a simple FileList is used as a kind of "PlayList", but that can be changed easily to any List-Control
      If Not FGM Is Nothing Then FGM.Stop
      Set FGM = New FilgraphManager
          FGM.RenderFile File1.Path & "\" & File1.FileName
          FGM.Run
    End Sub
    HTH

    Olaf
    I get Automation error -2147220968 (80040218) at the line:
    Code:
    FGM.RenderFile File1.Path & "\" & File1.FileName
    Here there is information.

    But I'm able to play them fine with Windows Media Player, BSPlayer or VLC.
    Last edited by Eduardo-; Jun 29th, 2017 at 02:34 AM.

  13. #13
    PowerPoster
    Join Date
    Jun 2013
    Posts
    7,253

    Re: Play audio files

    Quote Originally Posted by Eduardo- View Post
    I get Automation error -2147220968 (80040218) at the line:
    Code:
    FGM.RenderFile File1.Path & "\" & File1.FileName
    Then it can't build the graph automatically (never experienced that for MP3-Files) - maybe it's messed
    up registry-entries for the DirectShow-Filters (which can happen, e.g. when you installed things like
    "KLite-CodecPack" or other such "collections")...

    What happens when you run it from a compiled executable (not in "Admin-mode" like the VB6-IDE)?

    Olaf

  14. #14

    Thread Starter
    PowerPoster
    Join Date
    Feb 2017
    Posts
    5,064

    Re: Play audio files

    Quote Originally Posted by Schmidt View Post
    Then it can't build the graph automatically (never experienced that for MP3-Files) - maybe it's messed
    up registry-entries for the DirectShow-Filters (which can happen, e.g. when you installed things like
    "KLite-CodecPack" or other such "collections")...
    This Windows installation is a bit aged so may be I did at some point.

    Quote Originally Posted by Schmidt View Post
    What happens when you run it from a compiled executable (not in "Admin-mode" like the VB6-IDE)?

    Olaf
    The same error.

    Anyway this is a good example of the kind of situations that I don't want to have with users.

  15. #15

  16. #16

    Thread Starter
    PowerPoster
    Join Date
    Feb 2017
    Posts
    5,064

    Re: Play audio files

    Hello The Trick, thank you.
    I tried your "Playing MP3 from file/memory using DirectSound" project, and I reported a problem in that thread.

  17. #17

    Thread Starter
    PowerPoster
    Join Date
    Feb 2017
    Posts
    5,064

    Re: Play audio files

    Thanks guys, i think i'm coming to a conclusion, to a decision:

    Let the user choose between two options that he will be able to configure:
    A) To open the folder where the audio files are.
    B) To reproduce them with Windows Media Player.

    For B) i still need to find out how to do it, and also how to add files to the queue.
    Also to check for the rare case that WMP is not available or not able to reproduce mp3.

  18. #18

    Thread Starter
    PowerPoster
    Join Date
    Feb 2017
    Posts
    5,064

    Re: Play audio files

    Quote Originally Posted by Eduardo- View Post
    For B) i still need to find out how to do it, and also how to add files to the queue.
    This seems to work:

    Code:
    Private Declare Function ShellExecute Lib "shell32.dll" Alias "ShellExecuteA" (ByVal hWnd As Long, ByVal lpOperation As String, ByVal lpFile As String, ByVal lpParameters As String, ByVal lpDirectory As String, ByVal nShowCmd As Long) As Long
    Private Const SW_SHOW As Long = 5
        
        ' In the procedure that will open WMP:
        Call ShellExecute(0&, "OPEN", "wmplayer.exe", iStrListOfFilesEnclosedInDoubleQuotesAndSeparatedBySpaces, "", SW_SHOW)
    That can be implemented:

    Code:
    Private Sub Command1_Click()
        Dim iFolder As String
        Dim iFileName As String
        Dim iStrList As String
        
        iFolder = "D:\Audio Files\Specific item\"
        Do Until iFileName = ""
            If iStrList <> "" Then iStrList = iStrList & " "
            iStrList = iStrList & Chr(34) & iFolder & iFileName & Chr(34)
            iFileName = Dir
        Loop
        
        Call ShellExecute(0&, "OPEN", "wmplayer.exe", iStrList, "", SW_SHOW)
    
    End Sub
    Quote Originally Posted by Eduardo- View Post
    Also to check for the rare case that WMP is not available or not able to reproduce mp3.
    That's still pending.
    Last edited by Eduardo-; Jun 30th, 2017 at 07:07 PM.

  19. #19

    Thread Starter
    PowerPoster
    Join Date
    Feb 2017
    Posts
    5,064

    Re: Play audio files

    Quote Originally Posted by Eduardo- View Post
    Also to check for the rare case that WMP is not available
    I think this is.

    Quote Originally Posted by Eduardo- View Post
    or not able to reproduce mp3
    ...

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