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?
 
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.
0
 
HiImGlenAuthor Commented:
Guess no one has a clue? Haven't been able to find help anywhere else either hm.
0
 
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.
0
Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

 
DragonSlayerCommented:
does the code work for you?
0
 
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.
0
 
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.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.