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.
Last edited by schoolbusdriver; Jun 30th, 2007 at 10:29 AM.
Reason: Version 5-1. Mod to ensure correct exit
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:
'vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv Start of settings vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv
'vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv Change these to suit vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv
'Set this to the Resource ID.
Const RES_FILE_ID = "TOWN.MID"
'Set this to decide if playback stops and unloads this form after playing ONCE.
'i.e. for use as a splash screen. Setting this to TRUE will override the LOOP_PLAYBACK
'setting. (Needs TimerProc).
Const AUTO_EXIT = False
'Set this to determine if the playback loops continuously.
'If you set this to TRUE, AUTO_EXIT must be set to FALSE for looping to occur.
Const LOOP_PLAYBACK = True
Public Sub Do_After_PlayBack()
'Put any code in here to do after frmMCISendString unloads.
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.
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.
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:
Public Sub EndPlaybackLoop()
'MANDATORY!! Stop playback and close the file.
CleanUp
'MANDATORY!! Destroy the timer when the form closes.
Call KillTimer(frmSplashScreen.hwnd, intTimerID)
'New. Check the temporary file exists.
If Dir(strTempMediaFile) = "" Then Exit Sub '<<------
'Remove the temporary file.
If strTempMediaFile <> "Error" Then Kill strTempMediaFile
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...
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
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.
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
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:
Option Explicit
'MODULE LEVEL CODE - modPlaylist.bas
'DO NOT ALTER. SEE MODULE modAllSettings FOR THE USER SETTINGS.
'Autoplay first-loop Flag.
Public boolFirstLoop As Boolean
'Resource list variables.
Private arrResList() As String 'Stores the Resource string table list.
Private intResIndex As Integer 'Stores the current Resource ID index.
Public Sub AutoPlaylist(AUTOPLAY As Boolean)
Dim intIndex As Integer
'Decide whether to play a playlist.
If AUTOPLAY = False Then Exit Sub
'Get the resource list.
arrResList = GetResources(201)
'Test for a secondary playlist.
If arrResList(0) = "Error" Then Exit Sub
If boolFirstLoop = True Then
intResIndex = 0
boolFirstLoop = False
Else
'Increment the counter...
intResIndex = intResIndex + 1
'...if it's reached the last element, return to the start.
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