version="1.1.6BEP" print "autoplay script version ";version;" started" REM REM autoplayer REM May 14, 2007 REM Copyright (c) 2006-2007 Roku, LLC. REM REM This BrightScript detects and autoplay's media as follows: REM 1. If the video file autoplay.vob exists, it will play and loop forever. REM 2. If a playlist file autoplay.bsp is found, the playlist is executed in "play list" mode REM 3. If a coma-seperated-value file autoplay.csv exists, it will autoplay in "state machine" mode REM REM If more than one autoplay file exists, then the behavior is non-deterministic. REM REM REM Init some constants REM RANDOM ' just to reset pseudo random number.. debug=-1 'set to -1 to turn on debug prints; 0 to turn them off root="\" LED1=2 ^ 18:LED2=2 ^ 19:LED3=2 ^ 20:LEDM=2 ^ 21 MEDEN=8 'media end REM audio_ouput values: ANALOG=0 USB=1 SPDIF=2 REM audio_mode values, (Options 0 and 1 only apply to video files; 2 applies to all audio sources) SURROUND=0 STEREO=1 NOAUDIO=2 REM REM scan the files in the root directory and look for an autoplay file REM rem dir = ListDir(root) rem if dir.Count()=0 then print"Unexpected Empty Directory":stop rem for i=1 to dir.Count() rem file=dir.RemoveHead() rem if debug then print "file: ";file rem if file="autoplay.vob" or file="autoplay.mpg" then play_vid rem if file="autoplay.csv" then play_csv rem if file="autoplay.bsp" then play_bsp rem next rem print "An autoplay file was not found." rem stop ' nothing to play file=ReadAsciiFile("autoplay.csv") file=ReadAsciiFile("autoplay.csv") ' does file exist? if file<>"" then play_csv file=ReadAsciiFile("autoplay.bsp") ' does file exist? if file<>"" then play_bsp goto play_vid 'assume there is video file REM REM ****************************************************************** REM ****************************************************************** REM autoplay.vob (simple video loop) REM ****************************************************************** REM ****************************************************************** REM play_vid: if debug then print "play_vid entered" video=CreateObject("roVideoPlayer") p=CreateObject("roMessagePort") video.SetLoopMode(true) okay=video.PlayFile(root+"autoplay.mpg") if okay=0 then okay=video.PlayFile(root+"autoplay.vob") if okay=0 then print "Error finding autoplay file" stop endif endif msg=wait(0, p) ' wait forever REM REM ****************************************************************** REM ****************************************************************** REM autoplay.bsp(BrightSign Playlist -- simple text file of files) REM ****************************************************************** REM ****************************************************************** REM play_bsp: if debug then print "play_bsp entered: ";f$ mode=0 image=0 video=0 REM REM create the message port REM In BrightScript, objects can send events (such as video finished playing) to a message port. REM The BrightScript can then Wait on the port for a message. REM p=CreateObject("roMessagePort") REM REM Create the videomode object. It is used to set the display resolution, eg. 1024x768 REM mode=CreateObject("roVideoMode") if type(mode)="rotINT32" then print "Unexpected error creating roVideoMode":stop REM REM create the GPIO control object (for testing buttons and setting lights) REM sw = CreateObject("roGpioControlPort") swp = CreateObject("roMessagePort") sw.SetPort(swp) REM REM set audio to be analog out of audio out 1 REM audiomode=STEREO audiochan=2 audiooutput=ANALOG audiovolume=100 REM REM Keep looping the autoplay.bsp file forever REM call_count=0 file="" ' sets type to string, from RO forever: f$="autoplay.bsp" gosub play_bsp2 goto forever REM REM play_bsp2 handles the playback of a single playlist: filename passed in f$ REM It is a subroutine that can be called recursivly REM play_bsp2: if debug then print "Starting at top of playlist file." if call_count>9 then print "Error: Too many nested playlist files":stop save_file(call_count) = file save_posn(call_count) = posn call_count=call_count+1 posn=1 file=ReadAsciiFile(f$) if file="" then print "Unexpected error reading '";f$;"'":stop REM REM Detect end of line type (Windows/Dos, Linux, and Mac are all different) REM eol$=chr(13)+chr(10) '/r/n, Windows/DOS File if instr(1, file, eol$)=0 then eol$=chr(13) '/r, Mac if instr(1, file, eol$)=0 then eol$=chr(10) '/n, Linux if instr(1, file, eol$)=0 then print "No EOL found in file 'autoplay.bsp'":stop endif endif endif eoln=len(eol$) REM double check the file has not got an unexpected eol char if debug then if eoln=1 then if eol$=chr(13) then if instr(1,file,chr(10))>0 then print "unsupported line termination sequence (unexpected /n)" stop endif else if instr(1,file,chr(13))>0 then print "unsupported line termination sequence (unexpected /r)" stop endif endif endif endif REM REM setup video object to play video if needed REM if type(video)<>"roVideoPlayer" then if instr(1, file, ".mpg")>0 or instr(1, file, ".vob")>0 then video=CreateObject("roVideoPlayer") if type(video)="rotINT32" then print "Unexpected error creating roVideoPlayer":stop if debug then print "video object created" video.SetLoopMode(false) video.SetPort(p) gosub setaudiomode 'using defaults set earlier endif endif REM REM setup audio object to play audio if needed REM if type(audio)<>"roAudioPlayer" then if instr(1, file, ".mp3")>0 then audio=CreateObject("roAudioPlayer") if type(audio)="rotINT32" 0 then print "Unexpected error creating roAudioPlayer":stop if debug then print "audio object created" audio.SetLoopMode(false) audio.SetPort(p) gosub setaudiomode 'using defaults set earlier endif endif REM REM setup image object to play files if needed REM if type(image)<>"roImagePlayer" then if instr(1, file, ".bmp")>0 then image=CreateObject("roImagePlayer") if type(image)="rotINT32" then print "Unexpected error creating roImagePlayer":stop if debug then print "image object created" slideinterval=3000 'default 3 seconds endif endif REM REM main playlist loop starts here. REM scan through the playlist, find each line in the playlist, and see if it is a built in REM command (eg "debug" or "print"). If not, try and play it as a media file. REM bsp_lp: line_end=instr(posn, file, eol$) if line_end=0 then 'eof reached with no eol remaining_string=mid(file, posn) if len(remaining_string)>0 then 'check for a string beyond the last eol tk$=remaining_string posn=posn+len(remaining_string) goto bsp_strip endif call_count=call_count-1 posn=save_posn(call_count) file=save_file(call_count) return ' exit subroutine afer popping saved posn/file (to allow recursion) endif tk$=mid(file, posn, line_end-posn) posn=line_end+eoln ' point to next line start bsp_strip: if right(tk$,1)=" " then tk$=left(tk$, len(tk$)-1):goto bsp_strip 'strip any spaces at end of line if len(tk$)=0 then bsp_lp 'ignore blank lines f$=root+tk$ ' f$ now contains the complete path to the file to play REM REM handle built in keyword/commands REM if tk$="debug" then debug=-1:goto bsp_lp if left(tk$, 3)="rem" then bsp_lp ' skip rem (arks) if left(tk$, 3)="REM" then bsp_lp ' skip REM (arks) if left(tk$, 6)="print " then print mid(tk$, 7):goto bsp_lp ' print to console if left(tk$, 10)="audiomode " then audiomode=val(mid(tk$, 11)):gosub setaudiomode:goto bsp_lp if left(tk$, 12)="audiooutput " then audiooutput=val(mid(tk$, 13)):gosub setaudiomode:goto bsp_lp if left(tk$, 10)="audiochan " then audiochan=val(mid(tk$, 11)):gosub setaudiomode:goto bsp_lp if left(tk$, 7)="volume " then audiovolume=val(mid(tk$, 7)):gosub setaudiomode:goto bsp_lp if left(tk$, 10)="videomode " then videomode$=mid(tk$, 11):gosub setvideomode:goto bsp_lp if left(tk$, 10)="imagemode " then imagemode=val(mid(tk$, 11)):gosub setimagemode:goto bsp_lp if left(tk$, 13)="slideinterval" then slideinterval=val(mid(tk$, 14))*1000:goto bsp_lp if left(tk$, 8)="lighton " then sw.SetOutputState(val(mid(tk$, 9)), 1):goto bsp_lp if left(tk$, 9)="lightoff " then sw.SetOutputState(val(mid(tk$, 10)), 0):goto bsp_lp if left(tk$, 13)="waitbuttonany" then gosub clear_btn_queue:wait(0, swp):goto bsp_lp if left(tk$, 6)="pause " then sleep(val(mid(tk$, 7))*1000):goto bsp_lp ' pause (seconds) REM add asyncplay? idea: file.bmp, file.mp (triggers them both?) if debug print "playing file: ";f$ REM REM video file? REM if right(f$,4)=".mpg" or right(f$,4)=".vob" then okay=video.PlayFile(f$) if okay=0 then print "VID: Error trying to play file: ";"'";f$;"'" if debug stop endif bspmsglp: msg=wait(0, p) ' wait for video end if type(msg)="roVideoEvent" then if msg.GetInt() = MEDEN then bsp_lp goto bspmsglp REM REM audio file? REM else if right(f$,4)=".mp3" then okay=audio.PlayFile(f$) if okay=0 then print "AUD: Error trying to play file: ";"'";f$;"'" if debug stop endif bspmsglp2: msg=wait(0, p) ' wait for file end if type(msg)="roAudioEvent" and msg.GetInt() = MEDEN then bsp_lp goto bspmsglp2 REM REM bitmap file? REM else if right(f$,4)=".bmp" then if debug then print "Display Image::";f$;"::";" (";slideinterval;")" okay=image.DisplayFile(f$) if okay=0 then print "BMP: Error trying to display file: ";"'";f$;"'" if debug stop endif sleep(slideinterval) goto bsp_lp REM REM playlist file? REM else if right(f$,4)=".bsp" then gosub play_bsp2 goto bsp_lp else print "Unsupported file type in file: ";f$ if debug stop endif goto bsp_lp REM REM Playlist code helper functions REM setvideomode: if debug then print "VIDEOMODE Set to: ";videomode$ ok=mode.SetMode(videomode$) if ok=0 then print "Error: Can't set VIDEOMODE to ::";videomode$;"::":'stop REMOVE REM return setimagemode: if type(image)="roImagePlayer" then if debug then print "IMAGEMODE Set to: ";imagemode ok=image.SetDefaultMode(imagemode) if ok=0 then print "Error: Can't set IMAGEMODE to ";imagemode:stop endif return setaudiomode: if type(video)="roVideoPlayer" then if debug then print "AUDIOMODE (VID): am";audiomode;", ao: ";audiooutput;", ac: ";audiochan;", vol: ";audiovolume video.SetAudioMode(audiomode) video.SetAudioOutput(audiooutput) video.MapStereoOutput(audiochan) ' 2 == audio 0 video.SetVolume(audiovolume) endif if type(audio)="roAudioPlayer" then if debug then print "AUDIOMODE (AUD): am";audiomode;", ao: ";audiooutput;", ac: ";audiochan;", vol: ";audiovolume audio.SetAudioOutput(audiooutput) audio.MapStereoOutput(audiochan) ' 2 == audio 0 audio.SetVolume(audiovolume) endif return clear_btn_queue: msg=swp.GetMessage():if type(msg)<>"rotINT32" then clear_btn_queue return REM REM ****************************************************************** REM ****************************************************************** REM autoplay.csv(state machine created in Excel and saved in CSV format) REM ****************************************************************** REM ****************************************************************** REM play_csv: if debug then print "play_csv entered" REM REM create objects and ports REM p = CreateObject("roMessagePort") sw = CreateObject("roGpioControlPort") sw.SetPort(p) video= CreateObject("roVideoPlayer") video.SetPort(p) image=CreateObject("roImagePlayer") REM REM Set Audio Port that audio will come out of REM video.SetAudioMode(STEREO) video.SetAudioOutput(ANALOG) video.MapStereoOutput(2) ' 2 == audio 0 video.SetVolume(100) preloadedimage="" istouch=false REM REM Main State Machine Starts Now REM gosub read_state_file state="" ' forces state to be type string. Works around a bug in BrightScript that the next line will trigger w/o this line. state=state_table(1,1) ' first state/file name new_state: if debug then print "new_state: state=";state REM ' Random media if left(state,4)="rnd:" then gosub play_random endif gosub lookup_state if debug then print"after lookup_state: state=";state;", idx=";stateidx playfile$=state_table(stateidx, 1) lm=1 ' default to loop on tiut=0 ' default timout off rem a timeout "goto stateidx" indicates video should timeout if toevent>0 then if state_table(stateidx, toevent)<>"" then tiut=toval rem a "video finish event" indicates video should not loop if videndevent>0 then if state_table(stateidx, videndevent)<>"" then lm=0 if right(playfile$, 4)=".bmp" then gosub play_image else if right(playfile$, 4)=".mpg" or right(playfile$, 4)=".vob" then gosub play_video video.StopClear() else print "Error: Unknown file type: ";playfile$:stop endif if timeouted<>0 then state=state_table(stateidx, toevent) else if vidfinished<>0 then state=state_table(stateidx, videndevent) else if butpressed <> -1 then state=state_table(stateidx, bu(butpressed)) else if touchpressed <> 0 then state=state_table(stateidx, touchpressed) endif goto new_state REM Play Random offer the possibility to playback a conditional media REM based on random number and percentage REM Syntax rnd:probablilty:firstmedia:secondmedia REM 5 bep1 bep2 REM 5 16 27 play_random: bep1=instr(5,state,":") bep2=instr(bep1+1, state, ":") media1=mid(state,bep1+1, bep2-bep1-1) media2=mid(state,bep2+1) bep2=(rnd(val(mid(state,5,bep1-1)))=1) state=media2 : print "The Random event is:";bep2; if bep2 then state=media1 Print" then playback ";state;" file" return REM REM Read the state file REM read_state_file: dim bu(12) dim state_table(100, 25) dim eloev(25) state_table(0,0)="" ' force typomatic array to "string". This works around a BrightScript bug. pp=1 flipelo=0 file=ReadAsciiFile("autoplay.csv") if file="" then print "Unexpected error reading 'autoplay.csv'":stop skip_blank: gosub get_next if nxtstr="" then skip_blank if nxtstr="END" then print "Error: Incomplete .csv file":stop else if nxtstr="VIDEOMODE" then gosub get_next if debug then print "VIDEOMODE Set to: ";nxtstr mode=CreateObject("roVideoMode") mode.SetMode(nxtstr) else if nxtstr="IMAGEMODE" then gosub get_next if debug then print "IMAGEMODE Set to: ";val(nxtstr) ok=image.SetDefaultMode(val(nxtstr)) if ok=0 then print "Error: Can't set IMAGEMODE to ";val(nxtstr):stop else if nxtstr="FLIPELO" then if debug then print "FLIPELO set" flipelo=1 else if nxtstr="EVENTS" then if debug then print "Reading events" goto do_event_line endif goto skip_blank do_event_line: gosub get_next if nxtstr<>"" then print "Error: cell after EVENTS should be blank.":stop numevents=1 scan_events: gosub get_next if nxtstr="STATE" then scan_state numevents=numevents+1 if left(nxtstr, 4)="elo:" then gosub add_elo_r:goto scan_events if left(nxtstr, 5)="elor:" then gosub add_elo_rect:goto scan_events if left(nxtstr, 5)="eloc:" then gosub add_elo_circle:goto scan_events if left(nxtstr, 6)="relor:" then gosub add_elo_rect_rollover:goto scan_events if left(nxtstr, 6)="reloc:" then gosub add_elo_circle_rollover:goto scan_events if left(nxtstr, 7)="button:" then gosub add_button:goto scan_events if left(nxtstr, 8)="timeout:" then gosub add_timeout:goto scan_events if left(nxtstr, 8)="videoend" then gosub add_videoend:goto scan_events print "Error: unknown event type in EVENTS line":stop goto scan_events scan_state: numstates=0 next_row: event_num=0 numstates=numstates+1 next_ev: event_num=event_num+1 gosub get_next if nxtstr="STATE" or nxtstr="END" then if event_num < numevents then for i=event_num to numevents state_table(numstates, i)="" if debug then print "numstates=";numstates;", i=";i next endif if nxtstr="END" then state_table(numstates+1, 1)="":return ' the ="" is to avoid a runtime error (bug) in is_okay_to_preload goto next_row endif state_table(numstates, event_num) = nxtstr if (event_num > numevents) then print "Error: state table has destination states without an event trigger":stop goto next_ev add_elo_r: if istouch=false then istouch=true t=CreateObject("roTouchScreen") t.SetPort(p) REM Puts up a cursor if a mouse is attached REM The cursor must be a 32 x 32 BMP REM The x,y position is the “hot spot” point t.SetCursorBitmap(root+"cursor.bmp", 16, 16) t.SetResolution(1024, 768) t.SetCursorPosition(512, 512) endif yp=instr(5, nxtstr, ":")+1 wp=instr(yp, nxtstr, ":")+1 hp=instr(wp, nxtstr, ":")+1 if yp=0 or wp=0 or hp=0 then print "Error: Invalid touch coordinates for ELO event":stop xval=val(mid(nxtstr, 5, yp-5-1)) yval=val(mid(nxtstr, yp, wp-yp-1)) wval=val(mid(nxtstr, wp, hp-wp-1)) hval=val(mid(nxtstr, hp)) if flipelo=1 then xval=1024-(xval+wval) yval=768-(yval+hval) endif t.AddRectangleRegion(xval,yval,wval,hval, numevents) eloev(numevents)=-1 ' remember where the touch events are in the columns for use in play_video and play_image return add_elo_rect: if istouch=false then istouch=true t=CreateObject("roTouchScreen") t.SetPort(p) REM Puts up a cursor if a mouse is attached REM The cursor must be a 32 x 32 BMP REM The x,y position is the “hot spot” point t.SetCursorBitmap(root+"cursor.bmp", 16, 16) t.SetResolution(1024, 768) t.SetCursorPosition(512, 512) endif yp=instr(6, nxtstr, ":")+1 wp=instr(yp, nxtstr, ":")+1 hp=instr(wp, nxtstr, ":")+1 if yp=0 or wp=0 or hp=0 then print "Error: Invalid touch coordinates for ELO event":stop xval=val(mid(nxtstr, 6, yp-6-1)) yval=val(mid(nxtstr, yp, wp-yp-1)) wval=val(mid(nxtstr, wp, hp-wp-1)) hval=val(mid(nxtstr, hp)) if flipelo=1 then xval=1024-(xval+wval) yval=768-(yval+hval) endif t.AddRectangleRegion(xval,yval,wval,hval, numevents) eloev(numevents)=-1 ' remember where the touch events are in the columns for use in play_video and play_image return add_elo_rect_rollover: if istouch=false then istouch=true t=CreateObject("roTouchScreen") t.SetPort(p) REM Puts up a cursor if a mouse is attached REM The cursor must be a 32 x 32 BMP REM The x,y position is the “hot spot” point t.SetCursorBitmap(root+"cursor.bmp", 16, 16) t.SetResolution(1024, 768) t.SetCursorPosition(512, 512) endif yp=instr(7, nxtstr, ":")+1 wp=instr(yp, nxtstr, ":")+1 hp=instr(wp, nxtstr, ":")+1 rp=instr(hp, nxtstr, ":")+1 rohip=instr(rp, nxtstr, ":")+1 rolop=instr(rohip, nxtstr, ":")+1 oxp=instr(rolop, nxtstr, ":")+1 oyp=instr(oxp, nxtstr, ":")+1 if yp=0 or wp=0 or hp=0 or rp=0 or rohip=0 or rolop=0 or oxp=0 or oyp=0 then print "Error: Invalid touch coordinates for ELO event":stop xval=val(mid(nxtstr, 7, yp-7-1)) yval=val(mid(nxtstr, yp, wp-yp-1)) wval=val(mid(nxtstr, wp, hp-wp-1)) hval=val(mid(nxtstr, hp)) roval=val(mid(nxtstr, rp, rohip-rp-1)) rohival=mid(nxtstr, rohip, rolop-rohip-1) roloval=mid(nxtstr, rolop, oxp-rolop-1) oxval=val(mid(nxtstr, oxp, oyp-oxp-1)) oyval=val(mid(nxtstr, oyp)) if flipelo=1 then xval=1024-(xval+wval) yval=768-(yval+hval) endif t.AddRectangleRegion(xval,yval,wval,hval, numevents) if roval=1 then t.EnableRollOver(numevents, rohival, roloval, true) t.SetRollOverOrigin(numevents, oxval, oyval) endif eloev(numevents)=-1 ' remember where the touch events are in the columns for use in play_video and play_image return add_elo_circle: if istouch=false then istouch=true t=CreateObject("roTouchScreen") t.SetPort(p) REM Puts up a cursor if a mouse is attached REM The cursor must be a 32 x 32 BMP REM The x,y position is the “hot spot” point t.SetCursorBitmap(root+"cursor.bmp", 16, 16) t.SetResolution(1024, 768) t.SetCursorPosition(512, 512) endif yp=instr(6, nxtstr, ":")+1 radiusp=instr(yp, nxtstr, ":")+1 rp=instr(radiusp, nxtstr, ":")+1 if yp=0 or radiusp=0 or rp=0 then print "Error: Invalid touch coordinates for ELO circle event":stop xval=val(mid(nxtstr, 6, yp-6-1)) yval=val(mid(nxtstr, yp, radiusp-yp-1)) radiusval=val(mid(nxtstr, radiusp, rp-radiusp-1)) if flipelo=1 then xval=1024-xval yval=768-yval endif t.AddCircleRegion(xval,yval,radiusval, numevents) eloev(numevents)=-1 ' remember where the touch events are in the columns for use in play_video and play_image return add_elo_circle_rollover: if istouch=false then istouch=true t=CreateObject("roTouchScreen") t.SetPort(p) REM Puts up a cursor if a mouse is attached REM The cursor must be a 32 x 32 BMP REM The x,y position is the “hot spot” point t.SetCursorBitmap(root+"cursor.bmp", 16, 16) t.SetResolution(1024, 768) t.SetCursorPosition(512, 512) endif yp=instr(7, nxtstr, ":")+1 radiusp=instr(yp, nxtstr, ":")+1 rp=instr(radiusp, nxtstr, ":")+1 rohip=instr(rp, nxtstr, ":")+1 rolop=instr(rohip, nxtstr, ":")+1 oxp=instr(rolop, nxtstr, ":")+1 oyp=instr(oxp, nxtstr, ":")+1 if yp=0 or radiusp=0 or rp=0 or rohip=0 or rolop=0 or oxp=0 or oyp=0 then print "Error: Invalid touch coordinates for ELO circle event":stop xval=val(mid(nxtstr, 7, yp-7-1)) yval=val(mid(nxtstr, yp, radiusp-yp-1)) radiusval=val(mid(nxtstr, radiusp, rp-radiusp-1)) roval=val(mid(nxtstr, rp, rohip-rp-1)) rohival=mid(nxtstr, rohip, rolop-rohip-1) roloval=mid(nxtstr, rolop, oxp-rolop-1) oxval=val(mid(nxtstr, oxp, oyp-oxp-1)) oyval=val(mid(nxtstr, oyp)) if flipelo=1 then xval=1024-xval yval=768-yval endif t.AddCircleRegion(xval,yval,radiusval, numevents) if roval=1 then 'MUST RESOLVE is flipelo required? t.EnableRollOver(numevents, rohival, roloval, true) t.SetRollOverOrigin(numevents, oxval, oyval) endif eloev(numevents)=-1 ' remember where the touch events are in the columns for use in play_video and play_image return add_button: bn=val(mid(nxtstr, 8)) if bn<0 or bn>12 then print "Error: invalid button number":stop if bu(bn)<>0 then print "Error: Button event used more than once":stop bu(bn) = numevents if debug then print "add_button: ";bn return add_timeout: toval=val(mid(nxtstr, 9))*1000 if toval<0 or toval>1000000 then print "Error: invalid timeout value":stop if toevent<>0 then print "Error: Only one timeout event allowed":stop toevent = numevents if debug then print "add_timeout: ";toval return add_videoend: if videndevent<>0 then print "Error: Only one videoend event allowed":stop videndevent = numevents if debug then print "add_videoend: " return get_next: np=instr(pp, file, ",")+1 if np=1 then if pp >= len(file) nxtstr="END":goto dognreturn np=len(file)+1:goto okay endif pvm=instr(pp+1, file, "VIDEOMODE"):if pvm<>0 and pvm < np then np=pvm:goto okay pim=instr(pp+1, file, "IMAGEMODE"):if pim<>0 and pim < np then np=pim:goto okay pfe=instr(pp+1, file, "FLIPELO"):if pfe<>0 and pfe < np then np=pfe:goto okay pev=instr(pp+1, file, "EVENTS"):if pev<>0 and pev < np then np=pev:goto okay pst=instr(pp+1, file, "STATE"):if pst<>0 and pst < np then np=pst okay: nxtstr=mid(file, pp, np-pp-1) pp=np strip1: if left(nxtstr,1)=" " then nxtstr=mid(nxtstr, 1): goto strip1 strip2: if right(nxtstr,1)=chr(13) or right(nxtstr,1)=chr(10) then nxtstr=left(nxtstr, len(nxtstr)-1): goto strip2 dognreturn: ' if debug then print "nxtstr: ";nxtstr return REM REM General Video Play Routine REM Call Parameters: REM lm 1 or 0 (loop mode on or off) REM playfile$ file path of video file to play REM tiut length of timeout in ms REM esc m-3 1 if button allowed, or zero if not REM play_video: if debug then print "Enter VideoPlay: ";playfile$;", loop=";lm;", timeout=";tiut butpressed=-1 vidfinished=0 timeouted=0 touchpressed=0 video.SetLoopMode(lm) REM the following didn't work - why?? ' if istouch=true then REM Enable mouse cursor if there is a touch event active in this state REM One touch event we assume to be an exit touch regioncount = 0 for i=1 to numevents if eloev(i) and state_table(stateidx, i)<>"" then regioncount = regioncount + 1 t.EnableRegion(i, true) else if istouch=true then t.EnableRegion(i, false) endif endif next if regioncount > 1 then t.EnableCursor(true) if debug then print "Cursor Enabled" else if istouch=true then t.EnableCursor(false) endif if debug then print "Cursor Disabled" endif ' endif labxx: tmp$="" if left(playfile$, len(root))<>root then tmp$=root tmp$=tmp$+playfile$ ok=video.PlayFile(tmp$) if ok=0 print "Error Playing File: ";tmp$:stop clear_queue: msg=p.GetMessage():if type(msg)<>"rotINT32" then clear_queue gosub is_okay_to_preload if preloadedimage<>"" then if left(preloadedimage, len(root))<>root then preloadedimage=root+preloadedimage ok=image.PreloadFile(preloadedimage) if ok=0 print "Error PreloadFile: ";preloadedimage:stop if debug then print "PreloadFile: ";preloadedimage endif vp_msg_loop: msg=wait(tiut, p) if type(msg)="roVideoEvent" then if debug then print "Video Event";msg.GetInt() if lm=0 AND msg.GetInt() = MEDEN then if debug then print "VideoFinished" vidfinished=1 return endif else if type(msg)="roTouchEvent" then if debug then print "Touch Event";msg if state_table(stateidx, msg)<>"" then touchpressed=msg:return else if type(msg)="roGpioButton" then if debug then print "Button Press";msg if bu(msg)>0 and state_table(stateidx, bu(msg))<>"" then butpressed=msg:return else if type(msg)="rotINT32" then if debug then print "TimeOut" timeouted=1 return else if debug then print "Unhandeled Event type: ";type(msg) endif goto vp_msg_loop play_image: if debug then print "Enter Play image: ";playfile$;", loop=";lm;", timeout=";tiut butpressed=-1 vidfinished=0 timeouted=0 touchpressed=0 regioncount=0 REM the following didn't work - why?? ' if istouch then REM Enable mouse cursor if there is a touch event active in this state REM Only enable touch regions that are active for this state for i=1 to numevents if eloev(i) and state_table(stateidx, i)<>"" then regioncount = regioncount + 1 t.EnableRegion(i, true) else if istouch then t.EnableRegion(i, false) endif endif next if regioncount > 0 then if playfile$<>"01_a.bmp" then t.EnableCursor(true) if debug then print "Cursor ENABLED" else if istouch then t.EnableCursor(false) endif if debug then print "Cursor Disabled" endif ' endif labyy: tmp$="" if left(playfile$, len(root))<>root then tmp$=root tmp$=tmp$+playfile$ if preloadedimage<>tmp$ then preloadedimage=tmp$ ok=image.PreloadFile(preloadedimage) if ok then ok=image.DisplayPreload() else ok=image.DisplayPreload() endif if ok=0 print "Error Playing File: ";preloadedimage:stop clear_queue2: msg=p.GetMessage():if type(msg)<>"rotINT32" then clear_queue2 gosub is_okay_to_preload if preloadedimage<>"" then if left(preloadedimage, len(root))<>root then preloadedimage=root+preloadedimage ok=image.PreloadFile(preloadedimage) if ok=0 print "Error PreloadFile: ";preloadedimage:stop if debug then print "PreloadFile: ";preloadedimage endif ip_msg_loop: msg=wait(tiut, p) if type(msg)="roTouchEvent" then if debug then print "Touch Event #";msg;" at ";msg.GetX()", ";msg.GetY() if state_table(stateidx, msg)<>"" then touchpressed=msg:return else if type(msg)="roGpioButton" then if debug then print "Button Press";msg if bu(msg)>0 and state_table(stateidx, bu(msg))<>"" then butpressed=msg:return else if type(msg)="rotINT32" then if debug then print "TimeOut" timeouted=1 return else if debug then print "Unhandeled Event type: ";type(msg) endif goto ip_msg_loop REM REM given a state name string, find its index REM lookup_state: for i=1 to numstates if state_table(i, 1)=state then stateidx=i:return next print "Error in lookup_state. State Not Found: ";state stop REM REM A. If this state only has one possible next bmp state, then preload it. REM B. If this state has more than one possible next bmp state, but one of them is the next row in the REM state table, then it is preloaded. REM is_okay_to_preload: prek=0 pokay=0 for i=2 to numevents if right(state_table(stateidx, i), 4)=".bmp" then prek=prek+1 if prek=1 then preloadedimage=state_table(stateidx, i) pokay=-1 else if preloadedimage<>state_table(stateidx, i) then pokay=0 endif endif next if pokay then return for i=2 to numevents if right(state_table(stateidx, i), 4)=".bmp" and state_table(stateidx, i) = state_table(stateidx+1, 1) then preloadedimage=state_table(stateidx+1, 1) return endif next preloadedimage="" return