video:Load() not working on Android

I’m building an app that plays several short videos on demand. It works perfectly when I build for IOS, but when I build for Android and try to play the video on any Android device I get an ERROR that says “Can’t play this video.” I am not pulling the videos from the internet. They reside on the device, that is, they are part of the app.

Any ideas? 

Here’s the code I’m using with Corona build 3179. I also tried it with build 3157 and got the same error.

video = native.newVideo( display.contentCenterX, display.contentCenterY, display.contentWidth, display.contentHeight ) sceneGroup:insert(video) video:load( "video.mp4" ) video:play() 

In the event anyone needs to see my build.settings here they are:

settings = { orientation = { default = "portrait", supported = { "portrait" } }, iphone = { xcassets = "Images.xcassets", plist = { UIApplicationExitsOnSuspend = false, UILaunchStoryboardName = "LaunchScreen", }, }, android = { usesPermissions = { "android.permission.INTERNET", }, }, plugins = { ["CoronaProvider.analytics.flurry"] = { publisherId = "com.coronalabs", }, }, }

It works great on IOS devices, but won’t play on Android devices.

Hope someone can help.

Thanks,

Guy

Can you zip up  your project and share it with us?

Rob

Rob,

I have attached a small downsized version of the project that when built plays videos on iPhones/iPads but when I load it onto an Android device I get the same error “Can’t play this video.”

I sure hope you are able to find the problem.

Thanks,

Guy

I got a different result. I’m using a Google Nexus 9 tablet running Android 7.1.1.  In the simulator, the video played, then cleared then showed the background buttons. On the device, the video played, but when it ended, the video was left on the screen.  Here’s the console log:

Dec 04 11:03:30.127 Android build succeeded in 42 seconds Dec 04 11:03:43.819 Installing and running VideoLoad on Nexus 9 23498 KB/s (10658493 bytes in 0.442s) Success Starting: Intent { cmp=com.coronalabs.rob.VideoLoad/com.ansca.corona.CoronaActivity } ---------- Device Log Starts ---------- Dec 04 11:03:45.363 Nexus 9: Platform: Nexus 9 Dec 04 11:03:45.363 / ARM Neon / 7.1.1 / NVIDIA Tegra / OpenGL ES 3.1 NVIDIA 343.00 / 2017.3179 / English | US | en\_US | en Dec 04 11:03:45.363 Nexus 9: WARNING: licensing.init() was already called for google. Dec 04 11:03:45.364 Nexus 9: Dec 04 11:03:45.385 WARNING: main.lua:37: audio.loadSound() failed to create sound 'clicksound.wav' Dec 04 11:03:45.386 Dec 04 11:03:45.404 Nexus 9: APP: Launched Nexus 9: APP: Test A - Started Dec 04 11:03:46.893 Nexus 9: videoCount 1 Dec 04 11:03:47.107 Nexus 9: Event phase: ready Dec 04 11:03:49.734 Nexus 9: Event phase: ended Dec 04 11:03:49.784 Nexus 9: WARNING: A.lua:343: audio.loadSound() failed to create sound 'whatshedoing.m4a' Dec 04 11:03:49.785 

It didn’t give me a “Can’t play this video” error. It played and ended. It failed to load the sound (which worked on the simulator) but that’s because Android doesn’t support m4a audio. 

What Android device/OS version are you trying this on?

Rob

Rob,

Thanks for the response. I’ve tried loading and running the app on an LG Trac-Phone Android version 4.4.2 and a Neutab 7in Android 5.1 Lollipop. They both give the same video error “Can’t play this video”. I’m glad the video will display on your device. I tried to update the operating system on the phone but I kept getting a message that there are no updates to be done. 

Do you have some idea as to what may be happening with the video? I mostly develop apps for IOS then port them to Android after I’ve gotten the bugs out of the IOS version. In the past I’ve not had any problems doing this until this time. 

Oh, and thanks for letting me know Android doesn’t support .m4a files. 

Thanks,

Guy

I found this in a Google Search:

Can you play mp4 on Android?

However, people still encounter the issue of  Android  won’t  play MP4. Why? The reason is  MP4  is a container format which means this format may contain various kinds of audio and video codecs while  Android  is only compatible with  MP4  encoded with MPEG-4 or H.264 AVC.May 6, 2010

So perhaps your video is using a different codec other than MPEG-4 or H.264 AVC.

As far as audio formats, what we support is documented here:
 

https://docs.coronalabs.com/guide/media/audioSystem/index.html#formats

Rob

Thanks Rob,

I suspect that is the problem. I’ll try converting the videos to the MPEG-4 format and see if the resolves the problem. 

Thanks again for your help,

Guy

I converted my videos to the correct MPEG-4 format per Android’s specifications. That did resolve the problem of the videos playing on IOS devices but not playing on some Android devices. However, I found there was still a problem. 

When the videos played on IOS they ended properly and the user was allowed to make another selection. But, on Android devices the videos would remain on the screen, even though they had completed playing. The last frame of the video would continue to display and the selection buttons that should display after the video completed were hidden behind it. 

I tried to resolve this problem by using video.isVisible = false. This did not work, it had no effect on my Android devices.

So, I tried using video.alpha = 0. Likewise this had no effect on any of my Android devices.

I was finally able to resolve the problem by moving the video off screen after it played by using video.y = 1000. When I needed it to play again I just moved it back using video.y = display.contentCenterY

The video.isVisible and video.alpha=0 worked just fine with IOS, but for some reason they were ignored with Android. I have no idea why, perhaps someone at Corona could take a look at it. 

If anyone else is having a similar problem then maybe moving the video off and on screen when needed will help you too.

Thanks Rob for your suggestions.

Guy

Can you zip up  your project and share it with us?

Rob

Rob,

I have attached a small downsized version of the project that when built plays videos on iPhones/iPads but when I load it onto an Android device I get the same error “Can’t play this video.”

I sure hope you are able to find the problem.

Thanks,

Guy

I got a different result. I’m using a Google Nexus 9 tablet running Android 7.1.1.  In the simulator, the video played, then cleared then showed the background buttons. On the device, the video played, but when it ended, the video was left on the screen.  Here’s the console log:

Dec 04 11:03:30.127 Android build succeeded in 42 seconds Dec 04 11:03:43.819 Installing and running VideoLoad on Nexus 9 23498 KB/s (10658493 bytes in 0.442s) Success Starting: Intent { cmp=com.coronalabs.rob.VideoLoad/com.ansca.corona.CoronaActivity } ---------- Device Log Starts ---------- Dec 04 11:03:45.363 Nexus 9: Platform: Nexus 9 Dec 04 11:03:45.363 / ARM Neon / 7.1.1 / NVIDIA Tegra / OpenGL ES 3.1 NVIDIA 343.00 / 2017.3179 / English | US | en\_US | en Dec 04 11:03:45.363 Nexus 9: WARNING: licensing.init() was already called for google. Dec 04 11:03:45.364 Nexus 9: Dec 04 11:03:45.385 WARNING: main.lua:37: audio.loadSound() failed to create sound 'clicksound.wav' Dec 04 11:03:45.386 Dec 04 11:03:45.404 Nexus 9: APP: Launched Nexus 9: APP: Test A - Started Dec 04 11:03:46.893 Nexus 9: videoCount 1 Dec 04 11:03:47.107 Nexus 9: Event phase: ready Dec 04 11:03:49.734 Nexus 9: Event phase: ended Dec 04 11:03:49.784 Nexus 9: WARNING: A.lua:343: audio.loadSound() failed to create sound 'whatshedoing.m4a' Dec 04 11:03:49.785 

It didn’t give me a “Can’t play this video” error. It played and ended. It failed to load the sound (which worked on the simulator) but that’s because Android doesn’t support m4a audio. 

What Android device/OS version are you trying this on?

Rob

Rob,

Thanks for the response. I’ve tried loading and running the app on an LG Trac-Phone Android version 4.4.2 and a Neutab 7in Android 5.1 Lollipop. They both give the same video error “Can’t play this video”. I’m glad the video will display on your device. I tried to update the operating system on the phone but I kept getting a message that there are no updates to be done. 

Do you have some idea as to what may be happening with the video? I mostly develop apps for IOS then port them to Android after I’ve gotten the bugs out of the IOS version. In the past I’ve not had any problems doing this until this time. 

Oh, and thanks for letting me know Android doesn’t support .m4a files. 

Thanks,

Guy

I found this in a Google Search:

Can you play mp4 on Android?

However, people still encounter the issue of  Android  won’t  play MP4. Why? The reason is  MP4  is a container format which means this format may contain various kinds of audio and video codecs while  Android  is only compatible with  MP4  encoded with MPEG-4 or H.264 AVC.May 6, 2010

So perhaps your video is using a different codec other than MPEG-4 or H.264 AVC.

As far as audio formats, what we support is documented here:
 

https://docs.coronalabs.com/guide/media/audioSystem/index.html#formats

Rob

Thanks Rob,

I suspect that is the problem. I’ll try converting the videos to the MPEG-4 format and see if the resolves the problem. 

Thanks again for your help,

Guy

I converted my videos to the correct MPEG-4 format per Android’s specifications. That did resolve the problem of the videos playing on IOS devices but not playing on some Android devices. However, I found there was still a problem. 

When the videos played on IOS they ended properly and the user was allowed to make another selection. But, on Android devices the videos would remain on the screen, even though they had completed playing. The last frame of the video would continue to display and the selection buttons that should display after the video completed were hidden behind it. 

I tried to resolve this problem by using video.isVisible = false. This did not work, it had no effect on my Android devices.

So, I tried using video.alpha = 0. Likewise this had no effect on any of my Android devices.

I was finally able to resolve the problem by moving the video off screen after it played by using video.y = 1000. When I needed it to play again I just moved it back using video.y = display.contentCenterY

The video.isVisible and video.alpha=0 worked just fine with IOS, but for some reason they were ignored with Android. I have no idea why, perhaps someone at Corona could take a look at it. 

If anyone else is having a similar problem then maybe moving the video off and on screen when needed will help you too.

Thanks Rob for your suggestions.

Guy