Problem with midis and TMediaPlayer.

For some reason my way of volume control is not affecting midi music but works perfect for .wav, .mp2, .mp3, .wma and .ogg files....

Also usually when a track is finished in my application it automatically go's to the next one, it has always worked with anything except midi files, nothing happens when track ends....

Here's what I use for changing volume:

Const
  // For Audio.
  MCI_SETAUDIO = $0873;
  MCI_DGV_SETAUDIO_ITEM = $00800000;
  MCI_DGV_SETAUDIO_VALUE = $01000000;
  MCI_DGV_SETAUDIO_VOLUME = $4002;
  MCI_DGV_STATUS_VOLUME = $4019;
 
Procedure TFrmMain.SetVolume(Var TMP: TCMediaPlayer; Const Volume: SmallInt);
Var
 p: MCI_DGV_SETAUDIO_PARMS;
Begin    // Volume: 0 - 1000.
    p.dwCallback := 0;
    p.dwItem := MCI_DGV_SETAUDIO_VOLUME;
    p.dwValue := Volume;
    p.dwOver := 0;
    p.lpstrAlgorithm := Nil;
    p.lpstrQuality := Nil;
    mciSendCommand(TMP.DeviceID, MCI_SETAUDIO,
    MCI_DGV_SETAUDIO_VALUE Or MCI_DGV_SETAUDIO_ITEM, Cardinal(@p));
End;

And here's how I test to see if the track has ended:
If (MP.Mode = mpPlaying) And (MP.Position >= MP.TrackLength[1]) Then // If song is finished. Begin ... ... ... etc End;

Anyone have any idea why these issues only arise on playing midi files? I suppose it isn't all that important but I would like to fix these problems.
HiImGlenAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

HiImGlenAuthor Commented:
Guess no one has a clue? Haven't been able to find help anywhere else either hm.
DragonSlayerCommented:
Perhaps this? *untested code*

const
  MCI_SET_VOLUME = $80000;

type
  MCI_SET_PARMS2 = record
    dwCallback: DWORD;
    dwTimeFormat: DWORD;
    dwSpeedFormat: DWORD;
    dwAudio: DWORD;
    dwLevel: DWORD;
    dwOver: DWORD;
    dwItem: DWORD;
    dwValue: DWORD;
  end;

... // code begins here

var
  parms: MCI_SET_PARMS2;
begin
  FillChar(parms, SizeOf(MCI_SET_PARMS2), 0);
  parms.dwAudio := MCI_SET_AUDIO_ALL;
  parms.dwLevel := Volume;
  mciSendCommand(TMP.DeviceID, MCI_SET, MCI_WAIT or MCI_SET_AUDIO or MCI_SET_VOLUME, Longint(@parms));
end;

Bear in mind, that this is some *very old code*... not sure if it works anymore. I've defined my own MCI_SET_PARMS because my old code couldn't compile anymore... seems like the current reference to MCI_SET_PARMS only has 3 items in the struct?



DragonSlayer.

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
DragonSlayerCommented:
The reason your code works is because it is *only* for Digital Audio.

If my above code doesn't work, your other option is to start using the mixer API.

Or alternatively, use DirectMusic :-)



DragonSlayer.
CompTIA Network+

Prepare for the CompTIA Network+ exam by learning how to troubleshoot, configure, and manage both wired and wireless networks.

DragonSlayerCommented:
does the code work for you?
HiImGlenAuthor Commented:
To be honest I haven't been able to test it let alone even fire up Delphi lately, been swamped with study.

I felt it was unfair though to just leave it open.
DragonSlayerCommented:
oh... in that case you could've just left a comment here saying you will be back after your studies (in a couple of days/weeks perhaps)? :-)

otherwise if this question is closed, other experts might not come in to put in their comments.
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Delphi

From novice to tech pro — start learning today.