0

roStorageHotplug not working expectedly

Hi!

I am trying to create a BrightScript that recognises automatically when a USB memory stick is attached or deattached from the player and then plays videos from the root folder of the USB stick.

I am using roStorageHotplug for this. It is connected to roMessagePort and I am waiting for the messages. However, the messages are never sent because the unmounting fails as the system is reading a video from the USB stick. Is there any way around this?

I managed to get it trigger one time randomly. After that when reattaching a usb stick, the program could not find the new files as in the mounting phase the new usb was assigned to storage/usb2 as according to it storage/usb1 was already existing. This is another problem I need to solve somehow?

Any ideas of either of these points? Or am I thinking about this in a too complicated way?

Best, Miro

2 comments

  • 0
    Avatar
    Bright Scripters

    Sounds like you could add a delay between the hot plug event and video playback.

    Something like sleep(1000)?

    If that doens't work then you might need to start a roTimer.

  • 0
    Avatar
    Miro

    Thanks for the reply.

    Here is my code where I tried different methods for triggering actions based on usb stick presence. Basically just extending the readymade autorun example that plays all the files from sd card.

    Do you mean I should add the delay in the roStorageAttached event?

    debug=true

    VideoResolution$="1920x1080x30p"




    v=CreateObject("roVideoPlayer")

    p=createobject("roMessagePort")

    log=CreateObject("roSystemLog")

    hotplug = CreateObject("roStorageHotplug")

    hotplug.SetPort(p)

    v.SetPort(p)

    v.SetVolume(50)

    'v.SetLoopMode("AlwaysLoop")




    mode = CreateObject("roVideoMode")

    mode.SetMode(VideoResolution$)




    count=0

    playcount=0

    countfound=0

    countMax=100

    usbPlugged=false

    DIM mylist[countMax]







    read:

    list=ListDir("USB1:/")




    for each file in list

    if ucase(right(file,3)) = "MOV" or ucase(right(file,3)) = "MP4" or ucase(right(file,3)) = "MPG" or ucase(right(file,3)) = "VOB" or ucase(right(file,2)) = "TS" then 

    mylist[countFound]= "USB1:/" + file

    log.SendLine(file)

    countFound=countFound+1

    endif

    next







    play:

    if countfound=0 then goto read

    if debug print mylist[count]

    ok=v.PlayFile(mylist[count])

    playcount=playcount+1




    'advancing count

    if count = countFound-1 then

    count=0

    else

    count = count+1

    endif










    if ok=0 then

    if debug then print "Playback failed"

    goto play

    endif




    loop:




    if hotplug.GetStorageStatus("SSD:").present then

    if not usbPlugged then

    usbPlugged = true

    log.SendLine("USB REMOVED MANUALLY")

    endif

    endif




    if not hotplug.GetStorageStatus("SSD:").present then

    if usbPlugged then

    usbPlugged = false

    log.SendLine("USB ADDED MANUALLY")

    endif

    endif




    msg=wait(0, p)




    if type(msg) = "roStorageDetached" then

    log.SendLine("USB DEVICE DEATTACHED")

    countfound = 0

    mylist.Clear()

    v.StopClear()

    endif




    if type(msg) = "roStorageAttached"

    log.SendLine("ATTACHED USB")

    endif




    if type(msg) = "roVideoEvent" then

    log.SendLine("VIDEO FINISHED PLAYBACK")

    if msg.GetInt() = 8 then

    goto play

    endif

    endif




    goto loop
Please sign in to leave a comment.