How to free the players for real ?

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
60 messages Options
123
Reply | Threaded
Open this post in threaded view
|

Re: How to free the players for real ?

jeremzw
Oh sorry simple player is working now...
Let me see why not in my code....
Reply | Threaded
Open this post in threaded view
|

Re: How to free the players for real ?

fredvs
Administrator
In reply to this post by jeremzw
Now I do not understand.

Here it works.

Did you ry o download all the uos project (click on download):
https://github.com/fredvs/uos/
Reply | Threaded
Open this post in threaded view
|

Re: How to free the players for real ?

fredvs
Administrator
In reply to this post by jeremzw
> Oh sorry simple player is working now...

Ha ok, je vais mieux.

Fre;D
Reply | Threaded
Open this post in threaded view
|

Re: How to free the players for real ?

jeremzw
In reply to this post by jeremzw
I'll be comparing my code and simple player and will tell you what happened !
Reply | Threaded
Open this post in threaded view
|

Re: How to free the players for real ?

fredvs
Administrator
OK, good luck.

Fre;D
Reply | Threaded
Open this post in threaded view
|

Re: How to free the players for real ?

jeremzw
Seems to work for my code now... Maybe I forgot to close / reopen Lazarus after replacing uos.pas.

Now, I'll check the initial problems (freeing threads) and see how it goes.
Reply | Threaded
Open this post in threaded view
|

Re: How to free the players for real ?

fredvs
Administrator
Ha, I am happy.

For your problem of threads not freed if only prepared with uos_stop(nplayer), please do this for those threads:

uos_playpaused(nplayer);
 uos_stop(nplayer);


I will fix this asap to only use  uos_stop(nplayer), without calling uos_playpaused(nplayer) before stop.

Fre;D
 
Reply | Threaded
Open this post in threaded view
|

Re: How to free the players for real ?

fredvs
Administrator
> I will fix this asap to only use  uos_stop(nplayer), without calling uos_playpaused(nplayer) before stop.

OK, fixed in last commits: 6b4931c..c43230d

Fre;D
Reply | Threaded
Open this post in threaded view
|

Re: How to free the players for real ?

jeremzw
Ok, we're getting close !

It seems that your updates have solved the problem of freeing the threads, thanks !
But I still want to try to use uos_EndProc, but it wouldn't let me :

type

  { TFrmDisco }

  TFrmDisco = class(TForm)

...
procedure ClosePlayer0;

  private
    { private declarations }

  public
    { public declarations }

  end;

...

Procedure TFrmDisco.ClosePlayer0;
var
   Lepath: string;
   aRow: integer;
begin
     aRow:=ListViewDisco.Row;
     Lepath:=ListViewDisco.Cells[11,aRow];
     Chargeson(0, LePath);
end;  


Procedure ChargeSon(nPlayer: integer; LePath: string);
var
...
begin
 uos_CreatePlayer(nPlayer);
     If Fileexists(LePath) then
        begin
             InputIndex1 := uos_AddFromFile(0, PChar(LePath), -1, 0, 1024);

             {$if defined(cpuarm)} // needs lower latency
             uos_AddIntoDevOut(0, -1, 0.3, -1, -1, 0, 1024, -1);
             {$else}
             uos_AddIntoDevOut(0, -1, -1, -1, -1, 0, 1024, -1);
             {$endif}

             uos_EndProc(0, @ClosePlayer0);

             uos_InputSetPositionEnable(0, InputIndex1, 1) ;
             uos_InputSetLevelEnable(0, InputIndex1, 3) ;

             uos_InputLength(0, InputIndex1);
             temptime:= uos_InputLengthTime(0, InputIndex1);

             DecodeTime(temptime, ho, mi, se, ms);
             FrmDisco.LabelTOT.tag:= integer(ms + 1000*se + 60000*mi + 3600000*ho);
             FrmDisco.LabelTOT.caption:= format('%.2d:%.2d:%.2d.%.3d', [ho, mi, se, ms]);


        end;          
end;

It's stuck on the uos_EndProc line, saying "identifier not found : ClosePlayer0", though I followed the exact same code than main_sp.pas
Reply | Threaded
Open this post in threaded view
|

Re: How to free the players for real ?

fredvs
Administrator
Hello.

Did you try with ChargeSon from TFrmDisco ?:

Procedure TFrmDisco.ChargeSon(nPlayer: integer; LePath: string);

You may try also with EndProcOnly.
That way you will use a "pure" procedure, not of object.
Something like this:

Procedure ClosePlayer0;
var
   Lepath: string;
   aRow: integer;
begin
     aRow:=ListViewDisco.Row;
     Lepath:=ListViewDisco.Cells[11,aRow];
     FrmDisco.Chargeson(0, LePath);
end;  

///

uos_EndProcOnly(0, @ClosePlayer0);

Fre;D




Reply | Threaded
Open this post in threaded view
|

Re: How to free the players for real ?

jeremzw
In reply to this post by jeremzw
Great ! Your solution worked many thanks !

What would be the interest of  uos_EndProcOnly ? Would it be better ?
Reply | Threaded
Open this post in threaded view
|

Re: How to free the players for real ?

fredvs
Administrator

> What would be the interest of  uos_EndProcOnly ? Would it be better ?

It is for convenience and only a matter of taste.

Fre;D
Reply | Threaded
Open this post in threaded view
|

Re: How to free the players for real ?

jeremzw
Sorry about that but I still have a question about EndProc :

When I browse the discotheque, I need to be able to edit the intro time or the ending time of a sound.
So until I click on another sound, I want to be able to play it as many time as I want, from the beginning, from the end of the intro, etc...
I first tried uos_playnofree, but then uos_inputseekseconds wouldn't work. Every command would play the sound from the beginning.

I'm now using uos_play, but since the player is freed with endproc, that's why I'm asking that the sound be reloaded with endproc.
Now they're a conflict when I stop first sound and click on a second sound. (The program becomes unresponsive, as with an endless loop).

CODE :

Procedure TFrmDisco.ChargeSon(nPlayer: integer; LePath: string);
var
  temptime: ttime;
  ho, mi, se, ms: word;
begin
     uos_CreatePlayer(nPlayer);
     If Fileexists(LePath) then
        begin
             InputIndex1 := uos_AddFromFile(0, PChar(LePath), -1, 0, 1024);

             {$if defined(cpuarm)} // needs lower latency
             uos_AddIntoDevOut(0, -1, 0.3, -1, -1, 0, 1024, -1);
             {$else}
             uos_AddIntoDevOut(0, -1, -1, -1, -1, 0, 1024, -1);
             {$endif}
             uos_EndProc(0, @ClosePlayer0);
             uos_InputSetPositionEnable(0, InputIndex1, 1) ;
             uos_InputSetLevelEnable(0, InputIndex1, 3) ;

             uos_InputLength(0, InputIndex1);
             temptime:= uos_InputLengthTime(0, InputIndex1);

             DecodeTime(temptime, ho, mi, se, ms);
             LabelTOT.tag:= integer(ms + 1000*se + 60000*mi + 3600000*ho);
             LabelTOT.caption:= format('%.2d:%.2d:%.2d.%.3d', [ho, mi, se, ms]);


        end;
end;

Procedure TFrmDisco.ClosePlayer0;
var
  Lepath: string;
  aRow: integer;
begin
    aRow:=ListViewDisco.Row;
    Lepath:=ListViewDisco.Cells[11,aRow];
    ChargeSon(0, LePath);
end;

//// This is when one of the buttons "Play" is clicked :
Procedure PlayFile(n : integer; nPos : single);
begin
     uos_InputSeekSeconds(n, InputIndex1, nPos);
     uos_Play(n);
end;    
   
//// This is when a sound is clicked on the discotheque list :
Procedure AfficheRow(aRow : integer);
...
uos_stop(0);
uos_FreePlayer(0);
If Fileexists(LePath) then FrmDisco.ChargeSon(0, LePath);


Reply | Threaded
Open this post in threaded view
|

Re: How to free the players for real ?

fredvs
Administrator
Hello.

Maybe with this?:

/// This is when one of the buttons "Play" is clicked :
Procedure PlayFile(n : integer; nPos : single);
begin
     uos_PlayPaused(n);  
     uos_InputSeekSeconds(n, InputIndex1, nPos);
     uos_Resume(n);
end;    

or this one?

/// This is when one of the buttons "Play" is clicked :
Procedure PlayFile(n : integer; nPos : single);
begin
     uos_PlayNoFree(n);  
     uos_InputSeekSeconds(n, InputIndex1, nPos);
end;    
Reply | Threaded
Open this post in threaded view
|

Re: How to free the players for real ?

fredvs
Administrator
This post was updated on .
/// This is when a sound is clicked on the discotheque list :
Procedure AfficheRow(aRow : integer);
...
uos_stop(0);
uos_FreePlayer(0);
If Fileexists(LePath) then FrmDisco.ChargeSon(0, LePath);

----------------------------------------------

[EDIT: Ok, it should work.]

Reply | Threaded
Open this post in threaded view
|

Re: How to free the players for real ?

fredvs
Administrator
Re-hello.

Ooops, I think I did answer too fast in previous mail.

Please ignore it.

But uos_FreePlayer(0) is needed only when using uos_playNoFree();


Fre;D
Reply | Threaded
Open this post in threaded view
|

Re: How to free the players for real ?

jeremzw
In reply to this post by jeremzw
Oh I see... it takes time to free one player that's why I should alternate between 0 & 1, like in Morse...

I'll try first with uos_playpaused, seems easier, thanks  !
Reply | Threaded
Open this post in threaded view
|

Re: How to free the players for real ?

fredvs
Administrator
> Oh I see... it takes time to free one player that's why I should alternate between 0 & 1, like in Morse...

No, I did not read good your code.

But yes if you use 2 players if you stop 1 and play 2 sure there will be less silence between stop + play than using 1 player only.
Reply | Threaded
Open this post in threaded view
|

Re: How to free the players for real ?

jeremzw
In reply to this post by jeremzw
I think you did read good my code. I'm only using player 0. That must be why it doesn't work !

Anyways, I think I'll try with playpaused.
Reply | Threaded
Open this post in threaded view
|

Re: How to free the players for real ?

jeremzw
Awesome news :

uos_playnofree
uos_inputseekseconds

is the right syntax order.

I think now everything's fixed, thanks a lot for your help !
123