Nightly build: Android Support for native.newVideo

I have noticed from the documentation of the nightly builds that the native.newVideo is now supported in Android devices. I really need to get this running. But on my tests it is not.

When I try to get a video playing on Android I get this error, using version 2013.1202.

W/dalvikvm( 7618): threadid=1: thread exiting with uncaught exception (group=0x40f932a0) E/SurfaceFlinger( 305): SurfaceFlinger translucent=0 isOpaque=1 isExternalDisplayLayer=0 isExternalBlockLayer0 E/SurfaceFlinger( 305): SurfaceFlinger translucent=1 isOpaque=0 isExternalDisplayLayer=0 isExternalBlockLayer0 E/SurfaceFlinger( 305): SurfaceFlinger translucent=0 isOpaque=1 isExternalDisplayLayer=0 isExternalBlockLayer0 D/KeyguardViewMediator( 325): setHidden false E/AndroidRuntime( 7618): FATAL EXCEPTION: main E/AndroidRuntime( 7618): java.lang.IllegalStateException E/AndroidRuntime( 7618): at android.media.MediaPlayer.prepareAsync(Native Method) E/AndroidRuntime( 7618): at android.widget.VideoView.openVideo(VideoView.java:239) E/AndroidRuntime( 7618): at android.widget.VideoView.access$2000(VideoView.java:51) E/AndroidRuntime( 7618): at android.widget.VideoView$6.surfaceCreated(VideoView.java:478) E/AndroidRuntime( 7618): at android.view.SurfaceView.updateWindow(SurfaceView.java:615) E/AndroidRuntime( 7618): at android.view.SurfaceView.access$000(SurfaceView.java:86) E/AndroidRuntime( 7618): at android.view.SurfaceView$3.onPreDraw(SurfaceView.java:178) E/AndroidRuntime( 7618): at android.view.ViewTreeObserver.dispatchOnPreDraw(ViewTreeObserver.java:707) E/AndroidRuntime( 7618): at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:1936) E/AndroidRuntime( 7618): at android.view.ViewRootImpl.doTraversal(ViewRootImpl.java:1105) E/AndroidRuntime( 7618): at android.view.ViewRootImpl$TraversalRunnable.run(ViewRootImpl.java:4462) E/AndroidRuntime( 7618): at android.view.Choreographer$CallbackRecord.run(Choreographer.java:725) E/AndroidRuntime( 7618): at android.view.Choreographer.doCallbacks(Choreographer.java:555) E/AndroidRuntime( 7618): at android.view.Choreographer.doFrame(Choreographer.java:525) E/AndroidRuntime( 7618): at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:711) E/AndroidRuntime( 7618): at android.os.Handler.handleCallback(Handler.java:615) E/AndroidRuntime( 7618): at android.os.Handler.dispatchMessage(Handler.java:92) E/AndroidRuntime( 7618): at android.os.Looper.loop(Looper.java:137) E/AndroidRuntime( 7618): at android.app.ActivityThread.main(ActivityThread.java:4895) E/AndroidRuntime( 7618): at java.lang.reflect.Method.invokeNative(Native Method) E/AndroidRuntime( 7618): at java.lang.reflect.Method.invoke(Method.java:511) E/AndroidRuntime( 7618): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:994) E/AndroidRuntime( 7618): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:761) E/AndroidRuntime( 7618): at dalvik.system.NativeStart.main(Native Method) E/SurfaceFlinger( 305): SurfaceFlinger translucent=0 isOpaque=1 isExternalDisplayLayer=0 isExternalBlockLayer0 E/SurfaceFlinger( 305): SurfaceFlinger translucent=1 isOpaque=0 isExternalDisplayLayer=0 isExternalBlockLayer0 E/SurfaceFlinger( 305): SurfaceFlinger translucent=1 isOpaque=0 isExternalDisplayLayer=0 isExternalBlockLayer0 E/SurfaceFlinger( 305): SurfaceFlinger translucent=0 isOpaque=1 isExternalDisplayLayer=0 isExternalBlockLayer0

Using today’s version 1208, it does not crash, but the video won’t open.

Thanks,

-a

Hello,

I have a similar problem. It crashes when I try to create the native.newVideo in Android (version 2013.1230). It works on iOS. Is it a problem of video format? What I’m doing wrong?

E/AndroidRuntime( 5530): FATAL EXCEPTION: main E/AndroidRuntime( 5530): java.lang.IllegalStateException E/AndroidRuntime( 5530): at android.media.MediaPlayer.prepareAsync(Native Method) E/AndroidRuntime( 5530): at android.widget.VideoView.openVideo(VideoView.java:225) E/AndroidRuntime( 5530): at android.widget.VideoView.access$2000(VideoView.java:49) E/AndroidRuntime( 5530): at android.widget.VideoView$6.surfaceCreated(VideoView.java:465) E/AndroidRuntime( 5530): at android.view.SurfaceView.updateWindow(SurfaceView.java:553) E/AndroidRuntime( 5530): at android.view.SurfaceView.access$000(SurfaceView.java:81) E/AndroidRuntime( 5530): at android.view.SurfaceView$3.onPreDraw(SurfaceView.java:169) E/AndroidRuntime( 5530): at android.view.ViewTreeObserver.dispatchOnPreDraw(ViewTreeObserver.java:590) E/AndroidRuntime( 5530): at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:1630) E/AndroidRuntime( 5530): at android.view.ViewRootImpl.handleMessage(ViewRootImpl.java:2459) E/AndroidRuntime( 5530): at android.os.Handler.dispatchMessage(Handler.java:99) E/AndroidRuntime( 5530): at android.os.Looper.loop(Looper.java:137) E/AndroidRuntime( 5530): at android.app.ActivityThread.main(ActivityThread.java:4514) E/AndroidRuntime( 5530): at java.lang.reflect.Method.invokeNative(Native Method) E/AndroidRuntime( 5530): at java.lang.reflect.Method.invoke(Method.java:511) E/AndroidRuntime( 5530): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:790) E/AndroidRuntime( 5530): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:557) E/AndroidRuntime( 5530): at dalvik.system.NativeStart.main(Native Method)

I’ve tried to play the video in the root of the system.ResourcesDirectory and it works. But when I download a video and I store it to a folder in the system.DocumentsDirectory Android shows the message “path is null”. iOS works perfect. Did anybody solved this problem?

Problem solved! On Android, if you your video is in the system.ResourceDirectory
it works, but if your video is in the system.DocumentsDirectory or in
the system.TemporaryDirectory it will not work if you write the load
function as in iOS. Here is the solution. I found it in the forums, but I
think it’s good to write it here too.

local videoPath = "folder/video.m4v" local video = native.newVideo(display.contentCenterX, display.contentCenterY, 720, 576 ) if (system.getInfo("platformName") == "Android") then video:load(system.pathForFile(videoPath, system.DocumentsDirectory)) else video:load(videoPath, system.DocumentsDirectory) end  

Great! Thanks for sharing. I had given up on this already and I’m using media.playVideo instead.

One unrelated question since you’re using this feature: do you really have to know the video size / aspect ration upfront or is there a way to detect it?

This is a bug.

The first one to file a bug report gets some special dchan lovin!

Hello,

I have a similar problem. It crashes when I try to create the native.newVideo in Android (version 2013.1230). It works on iOS. Is it a problem of video format? What I’m doing wrong?

E/AndroidRuntime( 5530): FATAL EXCEPTION: main E/AndroidRuntime( 5530): java.lang.IllegalStateException E/AndroidRuntime( 5530): at android.media.MediaPlayer.prepareAsync(Native Method) E/AndroidRuntime( 5530): at android.widget.VideoView.openVideo(VideoView.java:225) E/AndroidRuntime( 5530): at android.widget.VideoView.access$2000(VideoView.java:49) E/AndroidRuntime( 5530): at android.widget.VideoView$6.surfaceCreated(VideoView.java:465) E/AndroidRuntime( 5530): at android.view.SurfaceView.updateWindow(SurfaceView.java:553) E/AndroidRuntime( 5530): at android.view.SurfaceView.access$000(SurfaceView.java:81) E/AndroidRuntime( 5530): at android.view.SurfaceView$3.onPreDraw(SurfaceView.java:169) E/AndroidRuntime( 5530): at android.view.ViewTreeObserver.dispatchOnPreDraw(ViewTreeObserver.java:590) E/AndroidRuntime( 5530): at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:1630) E/AndroidRuntime( 5530): at android.view.ViewRootImpl.handleMessage(ViewRootImpl.java:2459) E/AndroidRuntime( 5530): at android.os.Handler.dispatchMessage(Handler.java:99) E/AndroidRuntime( 5530): at android.os.Looper.loop(Looper.java:137) E/AndroidRuntime( 5530): at android.app.ActivityThread.main(ActivityThread.java:4514) E/AndroidRuntime( 5530): at java.lang.reflect.Method.invokeNative(Native Method) E/AndroidRuntime( 5530): at java.lang.reflect.Method.invoke(Method.java:511) E/AndroidRuntime( 5530): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:790) E/AndroidRuntime( 5530): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:557) E/AndroidRuntime( 5530): at dalvik.system.NativeStart.main(Native Method)

I’ve tried to play the video in the root of the system.ResourcesDirectory and it works. But when I download a video and I store it to a folder in the system.DocumentsDirectory Android shows the message “path is null”. iOS works perfect. Did anybody solved this problem?

Problem solved! On Android, if you your video is in the system.ResourceDirectory
it works, but if your video is in the system.DocumentsDirectory or in
the system.TemporaryDirectory it will not work if you write the load
function as in iOS. Here is the solution. I found it in the forums, but I
think it’s good to write it here too.

local videoPath = "folder/video.m4v" local video = native.newVideo(display.contentCenterX, display.contentCenterY, 720, 576 ) if (system.getInfo("platformName") == "Android") then video:load(system.pathForFile(videoPath, system.DocumentsDirectory)) else video:load(videoPath, system.DocumentsDirectory) end  

Great! Thanks for sharing. I had given up on this already and I’m using media.playVideo instead.

One unrelated question since you’re using this feature: do you really have to know the video size / aspect ration upfront or is there a way to detect it?

This is a bug.

The first one to file a bug report gets some special dchan lovin!

I tried what you say with the same code but I just get black screen when running on Android (I haven’t tried on iOS).

The code is the same, although file at root of DocumentsDirectory:

local videoPath = “sampleipod.m4v”
local video = native.newVideo(display.contentCenterX, display.contentCenterY, 100, 100 )

if (system.getInfo(“platformName”) == “Android”) then
    video:load(system.pathForFile(videoPath, system.DocumentsDirectory))
else
    video:load(videoPath, system.DocumentsDirectory)
end

“sampleipod.m4v” is the file that can be downloaded from http://support.apple.com/kb/ht1425

On some previous attempts I was able to play Full HD mp4 recorded from Android video camera, with media.download() from ResourceDirectory since included as asset, but the file did not opened when placed in DocumentsDirectory either.

I’m using corona 20131202 (2013.8.28).

This is disapointing me.

Thanks for some further help.

If you get a black screen, you are likely getting an error.  Please look in your console log to see what is happening.  if you don’t know how to do that, please read this tutorial:

http://www.coronalabs.com/blog/2013/07/09/tutorial-basic-debugging/

This block of code doesn’t make much sense to me:

if (system.getInfo("platformName") == "Android") then     video:load(system.pathForFile(videoPath, system.DocumentsDirectory)) else     video:load(videoPath, system.DocumentsDirectory) end

For @pau7, the reason you can’t do this is that we can’t read .m4v files directly out of a .apk file on Android.  Please read:

http://docs.coronalabs.com/api/library/system/ResourceDirectory.html

for an explanation.  If you go down to a post by Joshua Quick, one of our engineers on this post:

http://forums.coronalabs.com/topic/34025-problem-with-networkrequest-using-post/

You will see where the shows a trick to get a JPEG file extracted.  This same trick will work for .m4v files.  This is kind of why the system.pathForFile() call works, it extracts the image.

In @centroijla’s case, it looks like the file is in the system.DocumentsDirectory which should be readable without the android case.  Just do a video.load(“filename”, system.DocumentsDirectory).

Rob

@Rob Miracle, thank you very much for the links with the explanation. Now I understand how it works!!! I just copied a code I found on the forums to make the app work and gave a solution to my client, but I didn’t understand what happened. Everything makes sense to me. Thank you!

@centroijla, look at the console to give us a clue.

I tried what you say with the same code but I just get black screen when running on Android (I haven’t tried on iOS).

The code is the same, although file at root of DocumentsDirectory:

local videoPath = “sampleipod.m4v”
local video = native.newVideo(display.contentCenterX, display.contentCenterY, 100, 100 )

if (system.getInfo(“platformName”) == “Android”) then
    video:load(system.pathForFile(videoPath, system.DocumentsDirectory))
else
    video:load(videoPath, system.DocumentsDirectory)
end

“sampleipod.m4v” is the file that can be downloaded from http://support.apple.com/kb/ht1425

On some previous attempts I was able to play Full HD mp4 recorded from Android video camera, with media.download() from ResourceDirectory since included as asset, but the file did not opened when placed in DocumentsDirectory either.

I’m using corona 20131202 (2013.8.28).

This is disapointing me.

Thanks for some further help.

If you get a black screen, you are likely getting an error.  Please look in your console log to see what is happening.  if you don’t know how to do that, please read this tutorial:

http://www.coronalabs.com/blog/2013/07/09/tutorial-basic-debugging/

This block of code doesn’t make much sense to me:

if (system.getInfo("platformName") == "Android") then     video:load(system.pathForFile(videoPath, system.DocumentsDirectory)) else     video:load(videoPath, system.DocumentsDirectory) end

For @pau7, the reason you can’t do this is that we can’t read .m4v files directly out of a .apk file on Android.  Please read:

http://docs.coronalabs.com/api/library/system/ResourceDirectory.html

for an explanation.  If you go down to a post by Joshua Quick, one of our engineers on this post:

http://forums.coronalabs.com/topic/34025-problem-with-networkrequest-using-post/

You will see where the shows a trick to get a JPEG file extracted.  This same trick will work for .m4v files.  This is kind of why the system.pathForFile() call works, it extracts the image.

In @centroijla’s case, it looks like the file is in the system.DocumentsDirectory which should be readable without the android case.  Just do a video.load(“filename”, system.DocumentsDirectory).

Rob

@Rob Miracle, thank you very much for the links with the explanation. Now I understand how it works!!! I just copied a code I found on the forums to make the app work and gave a solution to my client, but I didn’t understand what happened. Everything makes sense to me. Thank you!

@centroijla, look at the console to give us a clue.