Recent

Author Topic: MplayerControl position - no value returned?  (Read 8309 times)

jotkate

  • Newbie
  • Posts: 1
MplayerControl position - no value returned?
« on: June 18, 2015, 11:39:52 am »
Hello Everyone!
I am new to Pascal so sorry for any mistakes I make describing the subject. What I'm trying to get is the current position of movie I'm playing to make a loop of a certain part depending on RS232 commands I get. Playback and RS232 works fine, but I have a problem with movie position feedback. What I'm using is this procedure to test if i am recieving anything, and "i" which is declared as a single (global variable) is always zero:

procedure TForm1.MPlayerControl1Playing(ASender: TObject; APosition: single);
begin
     i:=MPlayerControl1.Position;
     Label1.Caption:=FloatToStr(i);
end;

Except for the time when i send a command from button click which is for example:
MPlayerControl1.Position:=10;

Then I get the position shown in Label1, but only for a split second - after MplayingControl1Playing updates the 'i" variable goes back to zero again.
Any help is greatly appreciated.

jc99

  • Hero Member
  • *****
  • Posts: 553
    • My private Site
Re: MplayerControl position - no value returned?
« Reply #1 on: June 21, 2015, 03:07:04 pm »
Maybe you have to call it in a timer,
If you use the mmsystem directly then you get the changing-event as a callback
see attached file

@moderator:
Please remove file (New file: see next post)
« Last Edit: June 22, 2015, 09:25:48 am by jc99 »
OS: Win XP x64, Win 7, Win 7 x64, Win 10, Win 10 x64, Suse Linux 13.2
Laz: 1.4 - 1.8.4, 2.0
https://github.com/joecare99/public
'~|    /''
,_|oe \_,are
If you want to do something for the environment: Twitter: #reduceCO2 or
https://www.betterplace.me/klimawandel-stoppen-co-ueber-preis-reduzieren

jc99

  • Hero Member
  • *****
  • Posts: 553
    • My private Site
Re: MplayerControl position - no value returned?
« Reply #2 on: June 22, 2015, 09:22:42 am »
Sorry,
in the last archive, the main file is missing, it's here :
http://forum.lazarus.freepascal.org/index.php/topic,28777.msg181087.html
or use this file.

About your problem with TMPlayerControl
the playing event is only called when the player starts, so you get the 0 value.
add a timer to your project (interval: 1000) disabled,
enable it in the playing event. And let the timer display the position.
PS: and disable it, when the song is finished.
« Last Edit: June 22, 2015, 01:09:38 pm by jc99 »
OS: Win XP x64, Win 7, Win 7 x64, Win 10, Win 10 x64, Suse Linux 13.2
Laz: 1.4 - 1.8.4, 2.0
https://github.com/joecare99/public
'~|    /''
,_|oe \_,are
If you want to do something for the environment: Twitter: #reduceCO2 or
https://www.betterplace.me/klimawandel-stoppen-co-ueber-preis-reduzieren

jc99

  • Hero Member
  • *****
  • Posts: 553
    • My private Site
Re: MplayerControl position - no value returned?
« Reply #3 on: July 06, 2015, 01:06:29 am »
OS: Win XP x64, Win 7, Win 7 x64, Win 10, Win 10 x64, Suse Linux 13.2
Laz: 1.4 - 1.8.4, 2.0
https://github.com/joecare99/public
'~|    /''
,_|oe \_,are
If you want to do something for the environment: Twitter: #reduceCO2 or
https://www.betterplace.me/klimawandel-stoppen-co-ueber-preis-reduzieren

benohb

  • Full Member
  • ***
  • Posts: 213
Re: MplayerControl position - no value returned?
« Reply #4 on: July 06, 2015, 03:29:41 am »
procedure TForm1.MPlayerControl1Playing(ASender: TObject; APosition: single);

mercury

  • Full Member
  • ***
  • Posts: 154
Re: MplayerControl position - no value returned?
« Reply #5 on: November 26, 2015, 07:08:25 am »
@jc99
Your PlayMidi using WindowsAPI not Mplayer. And not cross-platforms.
Why not use SDL with SDL_mixer? It's cross-platforms, also can load sound library.

jc99

  • Hero Member
  • *****
  • Posts: 553
    • My private Site
Re: MplayerControl position - no value returned?
« Reply #6 on: December 19, 2015, 11:09:17 am »
@jc99
Your PlayMidi using WindowsAPI not Mplayer. And not cross-platforms.
Why not use SDL with SDL_mixer? It's cross-platforms, also can load sound library.
Good idea.
I already have: "get rid of W-API-only-dependency" on my to-do list.
But I wanted to do it in a slinky way, no bloated framework with lot of extra libraries just to play some midi-files.

So my goal was to make one Exe that has it all, and runs on nearly all computers. No extra file/no extra dependency!

If you can manage this with SDL, feel free to make the changes, or post some code.
OS: Win XP x64, Win 7, Win 7 x64, Win 10, Win 10 x64, Suse Linux 13.2
Laz: 1.4 - 1.8.4, 2.0
https://github.com/joecare99/public
'~|    /''
,_|oe \_,are
If you want to do something for the environment: Twitter: #reduceCO2 or
https://www.betterplace.me/klimawandel-stoppen-co-ueber-preis-reduzieren

neseir

  • Newbie
  • Posts: 2
Re: MplayerControl position - no value returned?
« Reply #7 on: April 22, 2016, 03:22:25 pm »
Hi

Found this after i discovered a different problem with the position property. If you are using a different decimal seperator in windows than mplayer uses on its respons, it will always return 0.

My windows installation uses "," as decimal seperator while mplayer reports back the movies position using ".". The position property uses StrToFloatDef to format the respons and since the decimal seperator is "wrong" it defaults to 0.

Setting the DefaultFormatSettings.DecimalSeparator := '.' in the application solves this but can causes other problems.

//Eirik

Tharon

  • Jr. Member
  • **
  • Posts: 61
Re: MplayerControl position - no value returned?
« Reply #8 on: October 03, 2017, 12:06:21 pm »
I'm having the same problem with the duration and position properties.

Duration always return -1, and Position always return 0. And yes, i'm cheking them inside a timer  :D

Using the neiser trick with DefaultFormatSettings.DecimalSeparator i can read the duration property (so, he was correct about the format issue) but Position is still always 0.

 

TinyPortal © 2005-2018