Read Current Volume of mediaplayer

Moderator: Rathinagiri

User avatar
Clip2Mania
Posts: 99
Joined: Fri Jun 13, 2014 7:16 am
Location: Belgium

Read Current Volume of mediaplayer

Post by Clip2Mania »

Please look at the sample:

x:\hmg.3.3.1\SAMPLES\Controls\Player\PLAYER_2

I try to extend the example by reading the current setting of the volume
I can set the player volume with "Form_1.Player_1.Volume" but:
How can I read the current/initial volume?

nVal:=Form_1.Player_1.Volume gives an error, because apparently, the "Volume" property is read-only. (there's only a "_SetPlayerVolume" ?)
(unfortunately not indicated in the HMG Manual) :(

Other way?
User avatar
gfilatov
Posts: 1060
Joined: Fri Aug 01, 2008 5:42 am
Location: Ukraine
Contact:

Re: Read Current Volume of mediaplayer

Post by gfilatov »

Clip2Mania wrote:Please look at the sample:

x:\hmg.3.3.1\SAMPLES\Controls\Player\PLAYER_2

I try to extend the example by reading the current setting of the volume
I can set the player volume with "Form_1.Player_1.Volume" but:
How can I read the current/initial volume?

nVal:=Form_1.Player_1.Volume gives an error, because apparently, the "Volume" property is read-only. (there's only a "_SetPlayerVolume" ?)
(unfortunately not indicated in the HMG Manual) :(

Other way?
Hi,

You are right! It is a known limitation in a Player C-code in HMG.

There is a simple solution. Please add to your C-function MCIFUNC() in the source c_media.c the following line:

Code: Select all

...
      case 19: hb_retnl( MCIWndGetVolume( mcihand ) ); break;
and then get "Volume" property in your h_controlmisc.prg via a new property below

Code: Select all

...
      CASE Arg3 == "VOLUME"

         RetVal := _GetPlayerVolume ( Arg2 , Arg1 )
where

Code: Select all

*-----------------------------------------------------------------------------*
function _GetPlayerVolume ( ControlName , ParentForm )
*-----------------------------------------------------------------------------*
Local h , mVar, nMCIVolume
	mVar := '_' + ParentForm + '_' + ControlName
	h := _HMG_SYSDATA [3] [&mVar] 
	nMCIVolume := mcifunc ( h , 19 )
Return( nMCIVolume )
Hope that helps :idea:
Kind Regards,
Grigory Filatov

"Everything should be made as simple as possible, but no simpler." Albert Einstein
User avatar
bpd2000
Posts: 1207
Joined: Sat Sep 10, 2011 4:07 am
Location: India

Re: Read Current Volume of mediaplayer

Post by bpd2000 »

#pragma BEGINDUMP
#include
#include
#include “hbapi.h”
#include “hbapiitm.h”
#include
#include
HB_FUNC ( MCIFUNC )
{
HWND mcihand = (HWND) hb_parnl(1);
int func = hb_parni(2);
switch(func)
{
case 1: hb_retnl( MCIWndPlay(mcihand) ) ; break;
case 2: hb_retnl( MCIWndStop(mcihand) ) ; break;
case 3: hb_retnl( MCIWndPause(mcihand) ) ; break;
case 4: hb_retnl( MCIWndClose(mcihand) ) ; break;
case 5: MCIWndDestroy(mcihand) ; hb_retnl(0) ; break;
case 6: hb_retnl( MCIWndEject(mcihand) ) ; break;
case 7: hb_retnl( MCIWndEnd(mcihand) ) ; break;
case 8: hb_retnl( MCIWndHome(mcihand) ) ; break;
case 9: hb_retnl( MCIWndOpen(mcihand,hb_parc(3),NULL) ) ; break;
case 10: hb_retnl( MCIWndOpenDialog(mcihand) ) ; break;
case 11: hb_retnl( MCIWndPlayReverse(mcihand) ) ; break;
case 12: hb_retnl( MCIWndResume(mcihand) ) ; break;
case 13: MCIWndSetRepeat(mcihand,hb_parl(3) ) ; hb_retnl(0) ; break;
case 14: hb_retnl( MCIWndSetSpeed(mcihand,hb_parni(3)) ) ; break;
case 15: hb_retnl( MCIWndSetVolume(mcihand,hb_parni(3)) ) ; break;
case 16: MCIWndSetZoom(mcihand,hb_parni(3) ) ; hb_retnl(0) ; break;
case 17: hb_retnl( MCIWndGetLength(mcihand) ) ; break;
case 18: hb_retnl( MCIWndGetPosition(mcihand) ) ; break;
case 19: hb_retnl( MCIWndGetVolume(mcihand) ) ; break;
case 20: hb_retnl( MCIWndSeek(mcihand,hb_parni(3)) ) ; break;
default: hb_retnl( 0 ) ;
}
}
#pragma ENDDUMP
BPD
Convert Dream into Reality through HMG
User avatar
Clip2Mania
Posts: 99
Joined: Fri Jun 13, 2014 7:16 am
Location: Belgium

Re: Read Current Volume of mediaplayer

Post by Clip2Mania »

thanks! Additional question
gfilatov wrote: and then get "Volume" property in your h_controlmisc.prg via a new property below

Code: Select all

...
      CASE Arg3 == "VOLUME"

         RetVal := _GetPlayerVolume ( Arg2 , Arg1 )

In what function in h_controlmisc.prg is that, please?
User avatar
gfilatov
Posts: 1060
Joined: Fri Aug 01, 2008 5:42 am
Location: Ukraine
Contact:

Re: Read Current Volume of mediaplayer

Post by gfilatov »

Clip2Mania wrote: In what function in h_controlmisc.prg is that, please?
Hi,

It is the function GetProperty () 8-)

Code: Select all

Function GetProperty ( Arg1 , Arg2 , Arg3 , Arg4 , Arg5 , Arg6 , Arg7 , Arg8 )
...

    ElseIf Arg3 == 'LENGTH'

        RetVal := _GetPlayerLength ( Arg2 , Arg1 ) 

    ElseIf Arg3 == 'POSITION'

        RetVal := _GetPlayerPosition ( Arg2 , Arg1 )

    ElseIf Arg3 == 'VOLUME'        // ADD

         RetVal := _GetPlayerVolume ( Arg2 , Arg1 )   // ADD
...
Kind Regards,
Grigory Filatov

"Everything should be made as simple as possible, but no simpler." Albert Einstein
User avatar
bpd2000
Posts: 1207
Joined: Sat Sep 10, 2011 4:07 am
Location: India

Re: Read Current Volume of mediaplayer

Post by bpd2000 »

Find working sample
Replace source files, rebuild library and run example
Image
Attachments
PLAYER_3.rar
(115.42 KiB) Downloaded 369 times
BPD
Convert Dream into Reality through HMG
User avatar
Clip2Mania
Posts: 99
Joined: Fri Jun 13, 2014 7:16 am
Location: Belgium

Re: Read Current Volume of mediaplayer

Post by Clip2Mania »

Hi gfilatov,

modified everything as you mentioned, added the function to h_media.prg, rebuilt with BuildAllLib.bat, no errors when rebuilding.

Using bpd2000's call

_GetPlayerVolume( "Playername", "Formname" ) works,

however when I do "Form_1.Player_1.Volume" does not work ???
Attachments
PLAYER_2.rar
(982.57 KiB) Downloaded 391 times
User avatar
gfilatov
Posts: 1060
Joined: Fri Aug 01, 2008 5:42 am
Location: Ukraine
Contact:

Re: Read Current Volume of mediaplayer

Post by gfilatov »

Clip2Mania wrote: however when I do "Form_1.Player_1.Volume" does not work ???
Hi,

It is an expected behavior because you didn't update a header file with pseudo-OOP definitions.

Did you tried a function's calling equivalent
GetProperty( 'Form_1' , 'Player_1' , 'Volume' ) instead of pseudo-OOP using :?:
Kind Regards,
Grigory Filatov

"Everything should be made as simple as possible, but no simpler." Albert Einstein
User avatar
Clip2Mania
Posts: 99
Joined: Fri Jun 13, 2014 7:16 am
Location: Belgium

Re: Read Current Volume of mediaplayer

Post by Clip2Mania »

gfilatov wrote: It is an expected behavior because you didn't update a header file with pseudo-OOP definitions.
Ok, didn't know that. I am learning! ;)
gfilatov wrote: Did you tried a function's calling equivalent
GetProperty( 'Form_1' , 'Player_1' , 'Volume' ) instead of pseudo-OOP using :?:
I tried it just now, and this returns 'NIL'

As long as it works, it is fine.
Thank you and 'bpd2000' !
User avatar
Clip2Mania
Posts: 99
Joined: Fri Jun 13, 2014 7:16 am
Location: Belgium

Re: Read Current Volume of mediaplayer

Post by Clip2Mania »

gfilatov wrote: It is an expected behavior because you didn't update a header file with pseudo-OOP definitions.
Together we are strong :-)
Found the location to adapt:
in i_window.ch, change line 78 (add 'volume') to:

Code: Select all

#xtranslate <w> . \<c\> . \<p:Name,Length,Volume\> => GetProperty ( <"w">, \<"c"\> , \<"p"\> ) ;;
Again, thx for the help, guys!
I use this setting to save in an .ini file, so that next time I start my mediaplayer, it starts at the same volume I as last time.
Could this be added to the following 'official' release of hmg? ;)
Post Reply