karu's avatar
Level 1

How to play video from Laravel API?

Im using React native Expo setup to play a video with expo-av package. The file I'm trying to play is in Laravels \storage\app\public\Yomama.mp4. But I cant get the URL right.... tried

<Video
  source={{ uri: `${BASE_URL}/storage/dailyoffers/${currentOffer.video}` }}
  style={styles.video}
  useNativeControls
  resizeMode="contain"
  isLooping
  onError={handleVideoError}
  }}
/>

gives 404 error. Tried full path name still 404. I get Images from the public folder with no issues but apparently does Laravel handle video files as 'files' so it put them in storage folder. But Expo seem not be able to locate it.

Any ideas?

0 likes
3 replies
martinbean's avatar
Level 80

@karu The file needs to be publicly accessible.

You should probably also look into streaming videos on the web reliably, i.e. using adaptive bitrate encoding instead of just trying to serve a static MP4 that will be many megabytes or even gigabytes in size.

karu's avatar
Level 1

@martinbean Oh okay. I'll just relocate the saving path then.

yeah sounds reasonable. I'll look into it. thx for the tip!

karu's avatar
Level 1

@martinbean so i moved the file and i can access it from the browser with http://192.168.0.22:8000/videos/1_20240621_095747.mp4

but when i try to access it from react native i get

ERROR  Video loading error: ke.a0$d: java.net.ProtocolException: unexpected end of stream

i lowered the quality to 480p and still the same.

<Video
                  ref={video}
                  source={{
                    uri: `http://192.168.0.22:8000/videos/1_20240621_095747.mp4`,
                  }}
                  useNativeControls
                  resizeMode="contain"
                  isLooping
                  style={styles.video}
                  onError={handleVideoError}
                  onPlaybackStatusUpdate={setStatus}
                />

when i use expo url https://d23dyxeqlo5psv.cloudfront.net/big_buck_bunny.mp4 the video appears.

EDIT: Nevermind. it doenst work in the emulator in android studio but works on my phone. no idea why....

Please or to participate in this conversation.