I need to make this MCI code work (REsolved)

Just starting out? Need help? Post your questions and find answers here.
michaeled314
Enthusiast
Enthusiast
Posts: 340
Joined: Tue Apr 24, 2007 11:14 pm

I need to make this MCI code work (REsolved)

Post 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

Last edited by michaeled314 on Tue Oct 25, 2011 12:33 am, edited 4 times in total.
User avatar
netmaestro
PureBasic Bullfrog
PureBasic Bullfrog
Posts: 8451
Joined: Wed Jul 06, 2005 5:42 am
Location: Fort Nelson, BC, Canada

Re: Do I need to use DirectShow?

Post by netmaestro »

I remember a good code sample from the announcements forum:

http://www.purebasic.fr/english/viewtop ... 14&t=22824
BERESHEIT
michaeled314
Enthusiast
Enthusiast
Posts: 340
Joined: Tue Apr 24, 2007 11:14 pm

Re: Do I need to use DirectShow?

Post 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)
michaeled314
Enthusiast
Enthusiast
Posts: 340
Joined: Tue Apr 24, 2007 11:14 pm

Re: Do I need to use DirectShow?

Post by michaeled314 »

I am in very desperate need of suggestions, since I need to make some software for where I work.
Zach
Addict
Addict
Posts: 1675
Joined: Sun Dec 12, 2010 12:36 am
Location: Somewhere in the midwest
Contact:

Re: Do I need to use DirectShow?

Post 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 :mrgreen:


edit: I found inc's wrapper for PB4 (4.51 I think)

http://www.purebasic.fr/english/viewtop ... ow+Wrapper
User avatar
netmaestro
PureBasic Bullfrog
PureBasic Bullfrog
Posts: 8451
Joined: Wed Jul 06, 2005 5:42 am
Location: Fort Nelson, BC, Canada

Re: Do I need to use DirectShow?

Post by netmaestro »

hehe, that's the link I posted :mrgreen:
BERESHEIT
michaeled314
Enthusiast
Enthusiast
Posts: 340
Joined: Tue Apr 24, 2007 11:14 pm

Re: Do I need to use DirectShow?

Post 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.
michaeled314
Enthusiast
Enthusiast
Posts: 340
Joined: Tue Apr 24, 2007 11:14 pm

Re: I need to make this MCI code work

Post by michaeled314 »

Is it not working because I use the MCISendstring in a thread?
User avatar
ts-soft
Always Here
Always Here
Posts: 5756
Joined: Thu Jun 24, 2004 2:44 pm
Location: Berlin - Germany

Re: I need to make this MCI code work

Post 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
PureBasic 5.73 | SpiderBasic 2.30 | Windows 10 Pro (x64) | Linux Mint 20.1 (x64)
Old bugs good, new bugs bad! Updates are evil: might fix old bugs and introduce no new ones.
Image
michaeled314
Enthusiast
Enthusiast
Posts: 340
Joined: Tue Apr 24, 2007 11:14 pm

Re: I need to make this MCI code work

Post 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
Thorium
Addict
Addict
Posts: 1305
Joined: Sat Aug 15, 2009 6:59 pm

Re: I need to make this MCI code work

Post 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.
michaeled314
Enthusiast
Enthusiast
Posts: 340
Joined: Tue Apr 24, 2007 11:14 pm

Re: I need to make this MCI code work

Post 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
RASHAD
PureBasic Expert
PureBasic Expert
Posts: 4946
Joined: Sun Apr 12, 2009 6:27 am

Re: I need to make this MCI code work

Post 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
Egypt my love
michaeled314
Enthusiast
Enthusiast
Posts: 340
Joined: Tue Apr 24, 2007 11:14 pm

Re: I need to make this MCI code work

Post by michaeled314 »

Holy shit.. really now..? I change the case of SetAudio from setaudio and now it works
michaeled314
Enthusiast
Enthusiast
Posts: 340
Joined: Tue Apr 24, 2007 11:14 pm

Re: I need to make this MCI code work

Post 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
Post Reply