
print "version 1.8x - updates self"
'added image, audio playback
'SD only

delay=6000	'time between images
delay_init=delay
transition% = 0	'zero is no transition

v=CreateObject("roVideoPlayer")
a=CreateObject("roAudioPlayer")
i=CreateObject("roImagePlayer")
p=createobject("roMessagePort")
v.SetPort(p)
a.setport(p)
i.SetDefaultTransition(transition%)

'videomode settings below currently disabled
mode = CreateObject("roVideoMode")
mode.SetMode("ntsc-m")


start:
DIM mylist[1000]	'max list size
DIM mytype[1000]
'check for boot script in boot folder
if copyfile("SD:"+"/boot/boot.brs", "SD:"+"boot.brs") then
	mfg=CreateObject("roMfgTest")
	if type(mfg) = "roMfgTest" then
			if mfg.WriteBootFile("", "autorun.brs") then 
				ok = mfg.WriteBootFile("SD:boot.brs", "autorun.brs")
				if not ok print"Failed to write to boot location"

				if ok then
					DeleteFile("SD:/autorun.brs")
					DeleteFile("SD:/boot.brs")
					DeleteFile("SD:/boot/boot.brs")	
					print "Script Loaded to Memory"
				endif 
				sleep(5000)
				mfg=0
				RebootSystem()
			else
				print "failed to write to boot location"
				sleep(5000)
			endif


	endif

endif

filetype$=" "
count=0
position=0
size=0
list=ListDir("SD:/")


'add files to list
'------------------
for each file in list 
	if ucase(right(file,3)) = "MPG" or ucase(right(file,3)) = "WMV" or ucase(right(file,3)) = "MOV" or ucase(right(file,3)) = "MP4" or ucase(right(file,3)) = "VOB" or ucase(right(file,2)) = "TS" then 
		mylist[count]=ucase(file)
		mytype[count]="V"
		count=count+1
	endif
	
	if ucase(right(file,3)) = "MP3" or ucase(right(file,3)) = "WAV" then 
			mylist[count]=ucase(file)
			mytype[count]="A"
			count=count+1
	endif
	
	if ucase(right(file,3)) = "JPG" or ucase(right(file,3)) = "BMP" or ucase(right(file,3)) = "PNG" then 
		mylist[count]=ucase(file)
		mytype[count]="I"
		count=count+1
	endif
	
	
next
size=count
if mylist.count() = 0 then
	print "No Files Found"
	sleep(5000)
	goto start
endif


'sort files alphabetically
'---------------------------
    if size > 0 then
        for i% = size-1 to 1 step -1
            for j% = 0 to i%-1
                if mylist[j%] > mylist[j%+1] then
                    tmp = mylist[j%]
                    mylist[j%] = mylist[j%+1]
                    mylist[j%+1] = tmp
                    
                    ttmp$ = mytype[j%]
                    mytype[j%]=mytype[j%+1]
                    mytype[j%+1]=ttmp$
                    
                endif
            next
        next
    endif

print mylist

'Playfiles
'-----------
if size > 0 then 
	for x=0 to size-1
	
		if mytype[x] = "V" then	
			a.Stop()
			i.StopDisplay()
			ok = v.PlayFile("SD:/"+mylist[x])
			delay=0
		else if mytype[x] = "A" then
			v.StopClear()
			i.StopDisplay()
			ok = a.PlayFile("SD:/"+mylist[x])
			delay=0
		else if mytype[x] = "I" then
			ok = i.DisplayFile("SD:/"+mylist[x])
			v.StopClear()
			a.Stop()
			delay=delay_init
		endif
		
		if ok then
			loop:
			msg=wait(delay,p)
			if delay =0 then
				if type(msg)="roVideoEvent" or type(msg)="roAudioEvent" then
					if msg.GetInt() <> 8 then goto loop
				else
					goto loop
				endif
				
			endif
		endif
	next
endif
mylist=0
goto start


