Finally, here is a snippet from a movie application that uses the IR module; it demonstrates how alt
is useful for dealing with multiple events. This is only one of the functions of the movie module, so not everything is defined. It uses the Mpeg
module, which actually copies the MPEG data stream to the screen asynchronously. Its play
function takes, as one of its arguments, a channel; before starting to play it writes a string on the channel. An empty string indicates success at locating the movie; a non-empty string contains an error message. When it finishes, it writes another string.
movie(entry: ref Dbinfo, cc: chan of int) { i : int; m : Mpeg; b : ref Image; m = load Mpeg Mpeg->PATH; if (m == nil) return; # make a place on the screen w := screen.window(screen.image.r); mr := chan of string; s := m->play(w, 1, w.r, entry.movie, mr); if(s != "") return; # wait for the end of the movie # while watching for button pushes for(;;) { alt { <-mr => return; i = <- cc => case i { Ir->Select => m->ctl("stop"); Ir->Up or Ir->Dn => m->ctl("pause"); } } } }