Results 1 to 19 of 19

Thread: VB - mciSendString - audio/video playback / video splashscreen etc from resource file

  1. #1

    Thread Starter
    Fanatic Member schoolbusdriver's Avatar
    Join Date
    Jan 2006
    Location
    O'er yonder
    Posts
    1,020

    VB - mciSendString - audio/video playback / video splashscreen etc from resource file

    Normally you would use the PlaySound API to play and loop jingles in your application, say, as a splash screen showed, and do it from memory. Unfortunately, PlaySound does not play midi files, which is a shame because they are 10 to 100 times smaller than wave files.

    mciSendString on the other hand does play midi files, but does not have a working command to loop playback, or playback from memory. But it can play a variety of audio and video files.

    This code lets you play looping audio or video files on a form without controls, from temporary files. Just the main form and a resource file containing your audio/video is needed.

    You can now force people to watch a video while your app loads, play an irritating tune while your app (game?) runs etc. The code is fully documented.

    EDIT:- Up to Version 5.
    Attached Files Attached Files
    Last edited by schoolbusdriver; Jun 30th, 2007 at 10:29 AM. Reason: Version 5-1. Mod to ensure correct exit

  2. #2
    Just Married shakti5385's Avatar
    Join Date
    Mar 2006
    Location
    Udaipur,Rajasthan(INDIA)
    Posts
    3,747

    Re: VB - mciSendString - audio/video playback / video splashscreen etc from resource file

    what ur code doing??

  3. #3

    Thread Starter
    Fanatic Member schoolbusdriver's Avatar
    Join Date
    Jan 2006
    Location
    O'er yonder
    Posts
    1,020

    Re: VB - mciSendString - audio/video playback / video splashscreen etc from resource file

    I've made some changes to make it more user friendly and updated the attachment accordingly. You'll see the following on the main form "frmMCISendString". Just change them to suit.

    I can't include a video file in the resource file due to attachment size limitations. You can of, course, change "frmMCISendString"'s borders/size etc to suit. A video display will resize at the start of playback to fill the form
    VB Code:
    1. 'vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv Start of settings vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv
    2. 'vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv Change these to suit vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv
    3.  
    4. 'Set this to the Resource ID.
    5.    Const RES_FILE_ID = "TOWN.MID"
    6.  
    7. 'Set this to decide if playback stops and unloads this form after playing ONCE.
    8. 'i.e. for use as a splash screen. Setting this to TRUE will override the LOOP_PLAYBACK
    9. 'setting. (Needs TimerProc).
    10.    Const AUTO_EXIT = False
    11.  
    12. 'Set this to determine if the playback loops continuously.
    13. 'If you set this to TRUE, AUTO_EXIT must be set to FALSE for looping to occur.
    14.    Const LOOP_PLAYBACK = True
    15.  
    16. Public Sub Do_After_PlayBack()
    17. 'Put any code in here to do after frmMCISendString unloads.
    18.    MsgBox "Form2.show", vbOKOnly, "Do_After_PlayBack"
    19. End Sub
    20.  
    21. Public Sub Do_During_PlayBack()
    22. 'Put any code in here to do at the end of the first playback loop.
    23.    MsgBox "Me.Visible = False", vbOKOnly, "Do_During_PlayBack"
    24. End Sub
    25.  
    26. '^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ End of settings ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    27. '^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ End of settings ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

    EDIT:- For some strange reason, this picture is getting more downloads than the program If you want the CODE, download the attachment in Post #1.

    Last edited by schoolbusdriver; Apr 8th, 2009 at 06:50 AM. Reason: New image source

  4. #4
    Just Married shakti5385's Avatar
    Join Date
    Mar 2006
    Location
    Udaipur,Rajasthan(INDIA)
    Posts
    3,747

    Re: VB - mciSendString - audio/video playback / video splashscreen etc from resource file

    plese send zip file again

  5. #5
    Junior Member
    Join Date
    Jul 2006
    Location
    Warner Robins GA
    Posts
    27

    Re: VB - mciSendString - audio/video playback / video splashscreen etc from resource file

    EDITED: Text removed by ImDaFrEaK because I wrote some arragant crap here that was kinda rude.
    Last edited by ImDaFrEaK; Apr 3rd, 2007 at 10:15 AM.

  6. #6

    Thread Starter
    Fanatic Member schoolbusdriver's Avatar
    Join Date
    Jan 2006
    Location
    O'er yonder
    Posts
    1,020

    Re: VB - mciSendString - audio/video playback / video splashscreen etc from resource file

    @ ImDaFrEaK, I assume you are referring to the app in my signature (XP Video Wallpaper with Transparent Icons and Icon Text. Plays DVDs too!), not "mciSendString audio-video looping - Version 2.zip".

    Thanks for your comments on VideoStar anyway VideoStar doesn't work in the way that you think. The desktop you see is the ORIGINAL desktop - NOT a copy or clone. Although it's easy enough to display video like this, the problem was to do it with transparent icons under XP, and keep the CPU usage down. Both achieved . At some point I'll have to test it with Vista. I can remove some of the effects, such as the control bar - but as it can play commercial DVDs, I left the effects in the demo so that testers could play around with it. There is a help file which explains some of this (but no "trade secrets" ).Again thanks for your comments. Much appreciated

    Edit: I'd like to see a DX version of this. I've never used DX, so it would be an education!
    Last edited by schoolbusdriver; Jul 25th, 2006 at 01:50 PM.

  7. #7
    Member
    Join Date
    Apr 2007
    Posts
    44

    Re: VB - mciSendString - audio/video playback / video splashscreen etc from resource file

    thnx schoolbusdriver .....

  8. #8
    Junior Member
    Join Date
    Jul 2006
    Location
    Warner Robins GA
    Posts
    27

    Re: VB - mciSendString - audio/video playback / video splashscreen etc from resource file

    NP, i'll dig up the working version i made and send it to you via email with source code. I read my comment above and realized that I sounded FREAKIN COCKY and i apologize for that. Thanks for not bringing it back down on me. I wrote that A long time ago and never got a reply and can see why. I was newer to forum posting then and I have learned to re-read what I write before I post b/c I can't believe I wrote that so rudely.

    Anyways, you do have a nice program and if your not cloning the desktop then you gotta tickle me with some idea of how your doing it. I have not been able to find anything simple (not that i've been looking since then) that can capture the desktop. Maybe if I dig a little more I can find it but that will be a while b/c I'm on a new project. I'll definately come back to it again though I hope.

  9. #9
    Hyperactive Member
    Join Date
    Jun 2006
    Posts
    301

    Re: VB - mciSendString - audio/video playback / video splashscreen etc from resource file

    I have used this many times, but now I have a question:

    When stopping the music you use:
    Code:
    Call EndPlaybackLoop
    in the Form_Unload.

    What if I want to make a : Sound on/off button?

    IF I make a command button {CmdStopMusic} and use this code:
    Code:
    Call EndPlaybackLoop
    the music stops, but if I close the application then via the X in the right, red box: Error

  10. #10

    Thread Starter
    Fanatic Member schoolbusdriver's Avatar
    Join Date
    Jan 2006
    Location
    O'er yonder
    Posts
    1,020

    Re: VB - mciSendString - audio/video playback / video splashscreen etc from resource file

    Ahh! Never thought of that. The reason for the error is that the EndPlaybackLoop sub attempts to delete a temporary file that was deleted when the command button was clicked previously. Easily cured - change the EndPlaybackLoop sub as follows. I'll update the download to version 5:

    vb Code:
    1. Public Sub EndPlaybackLoop()
    2. 'MANDATORY!! Stop playback and close the file.
    3.    CleanUp
    4. 'MANDATORY!! Destroy the timer when the form closes.
    5.    Call KillTimer(frmSplashScreen.hwnd, intTimerID)
    6. 'New. Check the temporary file exists.
    7.    If Dir(strTempMediaFile) = "" Then Exit Sub '<<------
    8. 'Remove the temporary file.
    9.    If strTempMediaFile <> "Error" Then Kill strTempMediaFile
    10. End Sub

  11. #11

    Thread Starter
    Fanatic Member schoolbusdriver's Avatar
    Join Date
    Jan 2006
    Location
    O'er yonder
    Posts
    1,020

    Re: VB - mciSendString - audio/video playback / video splashscreen etc from resource file

    @ ImDaFrEaK. np. I think some of my emails disappeared into a black hole when I had probs a while back.
    Re VideoStar: A tickle hey ? Ok , See this thread:
    http://www.vbforums.com/showthread.p...highlight=html
    and this one:
    http://www.vbforums.com/showthread.p...hlight=desktop.
    VideoStar is a cross-breed of the methods I mention. Easy to implement, damn difficult to unload without trashing your settings, hence no code - I don't want to be sued... and I've yet to test it on Vista...

  12. #12
    New Member
    Join Date
    Feb 2008
    Posts
    6

    Re: VB - mciSendString - audio/video playback / video splashscreen etc from resource file

    hey there i created an mp3 player and i am useing mcisendstring i dont know how to jump to the next song or do a repeat can anyone help me here i am useing vb.net

  13. #13

    Thread Starter
    Fanatic Member schoolbusdriver's Avatar
    Join Date
    Jan 2006
    Location
    O'er yonder
    Posts
    1,020

    Re: VB - mciSendString - audio/video playback / video splashscreen etc from resource file

    Actually, I've done a conversion on this app to VB.Net 2008, and the code is to start, stop and loop is almost the same. mciSendString doesn't have a command to loop music, so you have to get the file playing time and use that to stop playback. ie

    1) Get the file playing time.
    Start a timer which stops playback after the time obtained above.
    Start playback.

    2) When the timer triggers, stop playback and close the file.

    From this point you can do whatever you want. Simply repeat the steps above for any file - including the file that's just played (for looped music).

    Is there any particular problem you're having ? Post your code.

  14. #14
    New Member
    Join Date
    Feb 2008
    Posts
    6

    Re: VB - mciSendString - audio/video playback / video splashscreen etc from resource file

    ok i did a repeat but it only repeat one song not all also it doesn't auto start like i want it to i mean i got everything set but no loop or auto start or fastforward

  15. #15
    New Member
    Join Date
    Feb 2008
    Posts
    6

    Re: VB - mciSendString - audio/video playback / video splashscreen etc from resource file

    and how can i auto select the file once its uploaded

  16. #16

    Thread Starter
    Fanatic Member schoolbusdriver's Avatar
    Join Date
    Jan 2006
    Location
    O'er yonder
    Posts
    1,020

    Re: VB - mciSendString - audio/video playback / video splashscreen etc from resource file

    To loop a playlist, you can store a list of file names in an array, then increment a counter to retrieve the next element of that array. A later version of this app does precisely that. The playlist in this case is stored in the resource file. The following is only a small part of the later version, but shows how to use a playlist (stored in a resource file)

    String table in resource file:

    Code:
    200	Video list. Used for autoplay. These can be set to play in a loop. This resource file has an auto-playlist.	
    201	320.240.Bootylicious.wmv	
    202	320.240.Shake.wmv	
    203	320.240.Toccata.wmv	
    204	320.240.Drill.wmv	
    205	320.240.Cops.wmv
    vb Code:
    1. Option Explicit
    2.  
    3. 'MODULE LEVEL CODE - modPlaylist.bas
    4. 'DO NOT ALTER. SEE MODULE modAllSettings FOR THE USER SETTINGS.
    5.  
    6. 'Autoplay first-loop Flag.
    7. Public boolFirstLoop As Boolean
    8.  
    9. 'Resource list variables.
    10. Private arrResList() As String   'Stores the Resource string table list.
    11. Private intResIndex  As Integer  'Stores the current Resource ID index.
    12.  
    13. Public Sub AutoPlaylist(AUTOPLAY As Boolean)
    14.    Dim intIndex As Integer
    15.  
    16. 'Decide whether to play a playlist.
    17.    If AUTOPLAY = False Then Exit Sub
    18. 'Get the resource list.
    19.    arrResList = GetResources(201)
    20. 'Test for a secondary playlist.
    21.    If arrResList(0) = "Error" Then Exit Sub
    22.    If boolFirstLoop = True Then
    23.       intResIndex = 0
    24.       boolFirstLoop = False
    25.    Else
    26. 'Increment the counter...
    27.       intResIndex = intResIndex + 1
    28. '...if it's reached the last element, return to the start.
    29.       If intResIndex > UBound(arrResList) Then
    30.          intResIndex = 0
    31.       End If
    32.    End If
    33. 'Stop playback and close the file.
    34.    Call EndPlaybackLoop
    35. 'Start Playback.
    36.    Call BeginPlaybackLoop(arrResList(intResIndex), LOOP_PLAYBACK, AUTO_EXIT)
    37. End Sub
    38.  
    39. Public Function GetResources(intBase As Integer) As String()
    40.    Dim intIndex   As Integer
    41.    Dim strResList As String
    42.    
    43.    intIndex = intBase - 1
    44. 'The error will occur when there are no more items...
    45.    On Error GoTo errorDone
    46.    Do
    47. 'The first item is 101 so...
    48.       intIndex = intIndex + 1
    49.       strResList = strResList & LoadResString(intIndex) + vbCrLf
    50.    Loop
    51.    Exit Function
    52. errorDone:
    53.    If strResList = "" Then
    54.       strResList = "Error  "
    55.    End If
    56.    strResList = Left$(strResList, Len(strResList) - 2)
    57.    GetResources = Split(strResList, vbCrLf)
    58.    Exit Function
    59. End Function

    Never tried fast forward with mcisendstring - never needed to - however the "seek" command is what you need. For a list of commands look at Multimedia Command Strings. Also take a look at http://www.vbcode.com/Asp/showsn.asp?theID=2193

    Quote Originally Posted by Digital404
    and how can i auto select the file once its uploaded
    Not sure what you mean....

  17. #17
    New Member
    Join Date
    Feb 2008
    Posts
    6

    Re: VB - mciSendString - audio/video playback / video splashscreen etc from resource file

    OK lets say i upload a file i want it to be auto hightlighted
    Last edited by Digital404; Feb 14th, 2008 at 08:25 PM.

  18. #18
    New Member
    Join Date
    Feb 2008
    Posts
    6

    Re: VB - mciSendString - audio/video playback / video splashscreen etc from resource

    i'll go check out the strings you posted

  19. #19
    New Member
    Join Date
    Feb 2008
    Posts
    6

    Re: VB - mciSendString - audio/video playback / video splashscreen etc from resource

    i got the code working now once the music is done it switch to the next one but i have another question i added another project with this one called project 2 how can use both projects together like call up the project 2 mainfrm

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