Native video:load fails with media.selectVideo on Android

I’m trying to select a video using media.selectVideo. On the listener of the selectVideo call I try to load a native.newVideo with the returned event.url.

Something like:

local function selectFinished(event) local video = native.newVideo(0, 0, 640, 360) video:load(event.url, media.RemoteSource) end local options = { listener = selectFinished } media.selectVideo(options)

I tried setting the mediaSource to media.PhotoLibrary and media.savedPhotosAlbum and both didn’t work.

I noticed, that the returned event.url was a content url (content://com.android.providers.media.documents/document/video%3A253953) instead of a more familiar file:/// url returned from media.captureVideo or media.selectVideo on older devices.

Is there a way to get the file path from the content uri.

Or is it possible to copy the content uri to any of the system directories (i.e. Resource/Temporary/DocumentsDirectory)?

I’m using Corona build 2015.2644 with Android 5.1.1.

Hi @Appduction Studios,

Can you try the “video:load()” call without the second parameter, i.e. just pass “event.url”?

Thanks,

Brent

Hey Brent,

I tried removing media.RemoteSource, so just calling: video:load(event.url), and still nothing happened.

If selectVideo could return a file url, or if I could get a file or file url out of the content url, that would solve my problem.

Hi @Appduction Studios,

Just to confirm, you’re saying that the returned “event.url” is considerably different on this Android device/OS versus previous devices or OS versions? Are you sure that there’s not some setting on that device or within the OS that would be changing this? Some permission or otherwise?

Thanks,

Brent

Hey Brent,

I don’t think there are any special settings or permissions for that device.

I tested selectVideo on the following devices:

* Nexus 5 Android 5.1.1: returns content:// uri

* Nexus 7 Android 4.4.3: returns content:// uri

* LG Optimus L4 Android 4.1.2: returns file:/// uri

Is this an issue, that was introduced in Android 4.4? Both devices, that have this issue are running 4.4 or newer, while the only device, that returns a proper file url is running 4.1.2.

Hi @Appduction Studios,

OK, although the returned URL varies, it’s not 100% clear what’s not working. Have you tried playing the video using “media.playVideo()”? Have you checked the Android adb logcat to see if there are any errors popping up?

Brent

Hey Brent,

our main problem is, that we need to select a video and then upload it. The returned content uri is not really a file url, hence, I’m not sure how to upload it.

The video:load call does not return any errors in the adb logs, but still does not work.

Hello Brent,

Any news regarding this?

It is very crucial that we are able to load the selected video using native.newVideo and have a file URL which we can later upload to our server. This is already the case on iOS and Android prior to 4.4. Simply playing a selected video does not allow us to add the required features.

Best regards,
Shehab

We had a lengthy discussion with Engineering about this and as of right now, there is little we can do for Corona SDK to help with this.  It was designed for video playback in your app, not building a video sharing app.  We don’t have the bandwidth at this time to work on something more robust. 

There might be a way using Enterprise to do this, but it might be better to use Enterprise to capture the video in a way that lets it be more sharable.

Rob

Hey Rob,

Thanks for your feedback.

Let me just confirm that I understand you correctly. What you’re saying is that currently it is not possible to select a video on Android and load it with native.newVideo? Even though this is currently working on Android prior to 4.4 and all iOS versions? This kind of makes media.selectVideo obsolete on Android because why would anyone bother opening anything other than the default gallery to simply play a video?

Our problem is that this feature was already working, and once a user updates, it becomes completely broken. It’s a bit extreme don’t you think?

If you have suggestions or pointers on where to start with Enterprise regarding that, please let us know. Also if the team can just get the already existing functionality up to date with Android 4.4 and above that would be grand.

P.S.: When we capture a video we are able to load it using native.newVideo. It’s media.selectVideo that is acting up. Some moments just can’t be recaptured.

Kind regards,
Shehab

You should be able to select a video and play it with native.newVideo().  What you can’t do is upload a video taken with media.captureVideo() to some service.  You can’t get a copy into your system.DocumentsDirectory.  However I would think that media.selectVideo().

I can’t look into this right now, but later today I’ll see if I can get an example working.

Rob

local function onComplete( event ) if event.completed then local video = native.newVideo( display.contentCenterX, display.contentCenterY, 640, 360 ) local function videoListener( event ) print( "Event phase: " .. event.phase ) if event.errorCode then native.showAlert( "Error!", event.errorMessage, { "OK" } ) end end -- load a remote video video:load( event.url, media.RemoteSource ) video:addEventListener( "video", videoListener ) -- play video video:play() end end if media.hasSource( media.savePhotosAlbum) then media.selectVideo( { listener=onComplete, mediaSource=media.savePhotosAlbum } ) else native.showAlert( "Corona", "This device does not have a photo library.", { "OK" } ) end

This code worked on my Google Nexus 7.

Rob

Hi @Appduction Studios,

Can you try the “video:load()” call without the second parameter, i.e. just pass “event.url”?

Thanks,

Brent

Hey Brent,

I tried removing media.RemoteSource, so just calling: video:load(event.url), and still nothing happened.

If selectVideo could return a file url, or if I could get a file or file url out of the content url, that would solve my problem.

Hi @Appduction Studios,

Just to confirm, you’re saying that the returned “event.url” is considerably different on this Android device/OS versus previous devices or OS versions? Are you sure that there’s not some setting on that device or within the OS that would be changing this? Some permission or otherwise?

Thanks,

Brent

Hey Brent,

I don’t think there are any special settings or permissions for that device.

I tested selectVideo on the following devices:

* Nexus 5 Android 5.1.1: returns content:// uri

* Nexus 7 Android 4.4.3: returns content:// uri

* LG Optimus L4 Android 4.1.2: returns file:/// uri

Is this an issue, that was introduced in Android 4.4? Both devices, that have this issue are running 4.4 or newer, while the only device, that returns a proper file url is running 4.1.2.

Hi @Appduction Studios,

OK, although the returned URL varies, it’s not 100% clear what’s not working. Have you tried playing the video using “media.playVideo()”? Have you checked the Android adb logcat to see if there are any errors popping up?

Brent

Hey Brent,

our main problem is, that we need to select a video and then upload it. The returned content uri is not really a file url, hence, I’m not sure how to upload it.

The video:load call does not return any errors in the adb logs, but still does not work.

Hello Brent,

Any news regarding this?

It is very crucial that we are able to load the selected video using native.newVideo and have a file URL which we can later upload to our server. This is already the case on iOS and Android prior to 4.4. Simply playing a selected video does not allow us to add the required features.

Best regards,
Shehab

We had a lengthy discussion with Engineering about this and as of right now, there is little we can do for Corona SDK to help with this.  It was designed for video playback in your app, not building a video sharing app.  We don’t have the bandwidth at this time to work on something more robust. 

There might be a way using Enterprise to do this, but it might be better to use Enterprise to capture the video in a way that lets it be more sharable.

Rob