Page 1 of 2
I need to make this MCI code work (REsolved)
Posted: Mon Oct 24, 2011 1:41 am
by michaeled314
MCI does not work for me because while they support the MP3 file format with "mpegvideo" device mode, it is undocumented and when I try to use the "setaudio" command to change the volume, it gives me an MCI Error....
Does anybody have a simple example of using the DirectShow api?
Just in case you were wondering what I am talking about here is my code
Code: Select all
Structure FadeThread
Alias.s
Dur.l
StartVol.l
EndVol.l
EndStructure
Procedure SetMusicVolume(Alias.s,Volume.l) ;Volume is 1 to 1000
mciSendString_("setaudio "+Alias+" output",0,0,0)
Result = mciSendString_("setaudio "+Alias+" volume to"+Str(Volume),0,0,0)
text.s = Space(255)
mciGetErrorString_(result,@text,255)
Debug text
EndProcedure
Procedure FadeInMusic(*par.FadeThread)
For i = *par\StartVol To *par\EndVol
SetMusicVolume(*par\Alias,i)
Delay(*par\Dur)
Next
EndProcedure
FileName$ = OpenFileRequester("Choose a File:","","*.*",0)
If OpenMusic(FileName$, "Track001")
PlayMusic("Track001")
*par.FadeThread = AllocateMemory(SizeOf(FadeThread))
*par\Alias = "Track001"
*par\Dur = 5
*par\StartVol = 0
*par\EndVol = 1000
Repeat
Delay(7000)
CreateThread(@FadeInMusic(),*par)
a.s = GetTrackPos("Track001")
Debug a
Until a = ""
EndIf
Re: Do I need to use DirectShow?
Posted: Mon Oct 24, 2011 1:49 am
by netmaestro
I remember a good code sample from the announcements forum:
http://www.purebasic.fr/english/viewtop ... 14&t=22824
Re: Do I need to use DirectShow?
Posted: Mon Oct 24, 2011 1:54 am
by michaeled314
ugh, is there a simpler way to do this.. This seems like overkill for just wanting to open and play a file with sound adjustments (well I am planning to do more, but it would be great if I could have some reasonably short code to open a file and play it)
Re: Do I need to use DirectShow?
Posted: Mon Oct 24, 2011 3:19 pm
by michaeled314
I am in very desperate need of suggestions, since I need to make some software for where I work.
Re: Do I need to use DirectShow?
Posted: Mon Oct 24, 2011 6:08 pm
by Zach
Have you tried searching the forum?
There are a few example of DirectShow usage around here someone.. In fact I believe it was Inc. who wrote a DirectShow wrapper
However, have you tried using the Internal Movie library from PB? it has a short example in the help file.
I do wish they would update the Movie library with more commands though (Framestepping for one thing)
I was interested into writing a program to aid in Inverse Telecine operations for VFR Anime DVDs, but after trying to mess with the AVIfile and Directshow APIs I was quickly overwhelmed and gave up
edit: I found inc's wrapper for PB4 (4.51 I think)
http://www.purebasic.fr/english/viewtop ... ow+Wrapper
Re: Do I need to use DirectShow?
Posted: Mon Oct 24, 2011 6:18 pm
by netmaestro
hehe, that's the link I posted

Re: Do I need to use DirectShow?
Posted: Mon Oct 24, 2011 6:27 pm
by michaeled314
The code for the wrapper is chicken scratch to me.... Could someone tell me why my MCI code is not working, the functions OpenMusic() and CueMusic() are irrelevant, because they work perfectly. The song even plays. But I need to adjust the volume and it will not work.
Re: I need to make this MCI code work
Posted: Mon Oct 24, 2011 6:37 pm
by michaeled314
Is it not working because I use the MCISendstring in a thread?
Re: I need to make this MCI code work
Posted: Mon Oct 24, 2011 6:46 pm
by ts-soft
Volumesettings a complete changed in Vista or Seven, IMHO you can't change this with MCI in Vista or higher
Here is a german example for mastervolume:
http://www.purebasic.fr/german/viewtopi ... 09#p279909
Re: I need to make this MCI code work
Posted: Mon Oct 24, 2011 6:52 pm
by michaeled314
so then I need to change the master volume (like you do manually on the systray) to get a fade in effect and fade out also... I would rather not do that.. I tested it and it seems to work without the thread... But how would I not make the window freeze during the function call. And how do I run the main window loop while I run this function
Re: I need to make this MCI code work
Posted: Mon Oct 24, 2011 8:00 pm
by Thorium
MCI itself is outdated and you should not use it anymore. Use DirectShow with the posted examples or use the movielib.
There are many reasons why a MCI command fails on one system but works on another. First the right MCI drivers need to be installed and there are no new MCI drivers existing, so if something in new OS's changes the old driver may not fully work anymore and there are no new ones because MCI is abandoned.
Re: I need to make this MCI code work
Posted: Mon Oct 24, 2011 8:46 pm
by michaeled314
Then I request three things of anybody who wants to help:
1. I can't read this code if you put a gun to my head
2. My software does not play movies, so all the code involved with the movie aspect is useless to me
3. Can somebody write a little code example with the minimal amount of code you can to play a mp3 or wav or wma file with DirectShow
Re: I need to make this MCI code work
Posted: Mon Oct 24, 2011 9:27 pm
by RASHAD
Quick need more
Code: Select all
FileName$ = OpenFileRequester("","","ALL|*.*;*.mid|Wave|*.wav|mp3|*.mp3|OGG|*.OGG|MID|*.MID",0)
mciSendString_("OPEN "+Chr(34)+FileName$+Chr(34)+" Type MPEGVIDEO ALIAS "+Str(1),0,0,0) ;Open File
a$=Space(#MAX_PATH)
mciSendString_("Status "+Str(1)+" length",@a$,#MAX_PATH,0)
Length = Val(a$)
interval = Length / 1000
mciSendString_("SetAudio "+Str(1)+" volume to "+Str(5),0,0,0) ;Set Volume
mciSendString_("Play "+Str(1),0,0,0) ;Play
x = 5
Repeat
For i = 1 To interval
mciSendString_("SetAudio "+Str(1)+" volume to "+Str(x),0,0,0)
;mciSendString_("Play "+Str(1),0,0,0)
Delay(4000)
x = x + 10
Next
ForEver
Re: I need to make this MCI code work
Posted: Mon Oct 24, 2011 9:37 pm
by michaeled314
Holy shit.. really now..? I change the case of SetAudio from setaudio and now it works
Re: I need to make this MCI code work
Posted: Mon Oct 24, 2011 9:44 pm
by michaeled314
new code
Code: Select all
Structure FadeThread
Alias.s
Dur.l
StartVol.l
EndVol.l
EndStructure
ProcedureDLL SetMusicVolume(Alias.s,Volume.l) ;Volume is 1 to 1000
Result = mciSendString_("SetAudio "+Alias+" volume to "+Str(Volume),0,0,0)
text.s = Space(255)
mciGetErrorString_(result,@text,255)
Debug text
EndProcedure
ProcedureDLL.l GetTrackLength(Alias.s)
LengthStr.s = Space(255)
Result = mciSendString_("status "+Alias+" length",@LengthStr,255,0)
Length = Val(LengthStr)
If Not Result
ProcedureReturn Length
Else
ProcedureReturn #False
EndIf
EndProcedure
ProcedureDLL.s GetTrackPos(Alias.s)
Pos.s = Space(255)
Result = mciSendString_("status "+Alias+" position",@Pos,255,0)
Elapsed.l = Val(pos)
Minutes = Int(Elapsed/60000)
Seconds = Int(Elapsed/1000)%60
Milliseconds = Elapsed%1000
PosString.s = RSet(Str(Minutes),2,"0")+":"+RSet(Str(Seconds),2,"0")
If Not Result
ProcedureReturn PosString
Else
ProcedureReturn ""
EndIf
EndProcedure
ProcedureDLL.l OpenMusic(FileName.s,Alias.s)
Result = mciSendString_("open "+Chr(34)+FileName+Chr(34)+" type mpegvideo alias "+Alias,0,0,0)
If Not Result
ProcedureReturn #True
Else
ProcedureReturn #False
EndIf
EndProcedure
ProcedureDLL CueMusic(Alias.s, FromPos.l, ToPos.l, Vol.l)
mciStr.s = "cue "+Alias
If FromPos > -1
mciStr+" from "+Str(FromPos)
EndIf
If ToPos > -1
mciStr+" to "+Str(ToPos)
EndIf
Res1 = mciSendString_(mciStr,0,0,0)
If Vol > -1
SetMusicVolume(Alias,Vol)
EndIf
EndProcedure
ProcedureDLL.l PlayMusic(Alias.s)
Result = mciSendString_("play "+Alias+" notify",0,0,0)
If Not Result
ProcedureReturn #True
Else
ProcedureReturn #False
EndIf
EndProcedure
Procedure FadeInMusic(*par.FadeThread)
For i = *par\StartVol To *par\EndVol
SetMusicVolume(*par\Alias,i)
Delay(*par\Dur)
Next
EndProcedure
FileName$ = OpenFileRequester("Choose a File:","","*.*",0)
If OpenMusic(FileName$, "Track001")
Debug GetTrackLength("Track001")
PlayMusic("Track001")
*par.FadeThread = AllocateMemory(SizeOf(FadeThread))
*par\Alias = "Track001"
*par\Dur = 5
*par\StartVol = 0
*par\EndVol = 1000
Repeat
Delay(7000)
CreateThread(@FadeInMusic(),*par)
a.s = GetTrackPos("Track001")
Debug a
Until a = ""
EndIf
old !#$%^&* code
Code: Select all
ProcedureDLL SetMusicVolume(Alias.s,Volume.l) ;Volume is 1 to 1000
Result = mciSendString_("setaudio "+Alias+" volume to "+Str(Volume),0,0,0)
text.s = Space(255)
mciGetErrorString_(result,@text,255)
Debug text
EndProcedure
msdn docs
http://msdn.microsoft.com/en-us/library ... 85%29.aspx