Calibrate the Photo sensor input from Arduino and Trigger a video playback

I am a new user of Max. I would like to create a video trigger by photo sensor.

I would like to playback a video once the program start at full screen. ( Still haven’t figure out how to control an ext. display).

Then when the first photo sensor is being triggered. I would fade out the 1st video and then start the 2nd video for several seconds. When the photo sensor is continuously being trigger.. the video will playback until its end then go back to the 1st video.

Alternatively, if there is no trigger when playing 2nd video. It will go back to the first video.