• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 271
  • Last Modified:

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.
0
HiImGlen
Asked:
HiImGlen
  • 4
  • 2
1 Solution
 
HiImGlenAuthor Commented:
Guess no one has a clue? Haven't been able to find help anywhere else either hm.
0
 
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
 
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
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 
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

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

  • 4
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now