Note that there are some explanatory texts on larger screens.

plurals
  1. PODoes recursion good in that case? (javascript/node.js)
    primarykey
    data
    text
    <p>I m trying to make a TV from a raspberry pi, in javascript, the type who play the same playlist again and again. Playing the files aren t a problem, but I m stuck at the asynchronous part of javascript Here the code wich bother me:</p> <pre><code>function play (file) { exec('home/pi/play.sh', [file], function (error, stdout, stderr){ if (PIndice != Playlist.length-1){ PIndice=PIndice+1; }else{ PIndice=0; } play(Playlist[PIndice]); }); </code></pre> <p>Another function call it with Playlist[0] when I m sure there s a pathname in it.</p> <p>My question is: Is it safe? Isn t recursion will end up killing the cpu? I ve though about using setTimeOut but I didn t found any way to get the duration of the video.</p> <p>I ve tried calling play in a loop, but I just succeed at playing the whole playlist in the same time.</p> <p>I don t ask for a all-made solution, just hint to where I can find a way to do it properly Is there a way to wait for play to end before calling it again, even if javascript is asynchronous?</p> <p>EDIT: All files are in MPEG4, Playlist is just a array of string, wich contain the pathname of the video file to play. It s supposed to play without internet, so there s no browser, and I can t use html request to have the metadata of the video to get it duration.</p> <p>EDIT2: I forgot to tell that play.sh just start the player if there s no other instance of it, it is just a remain of the previous version where I didn t know about the callback of execFile</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload