Bug 20006 - RecordVideo sample does not work out of the box
Summary: RecordVideo sample does not work out of the box
Status: RESOLVED FIXED
Alias: None
Product: Android
Classification: Xamarin
Component: Samples ()
Version: 4.12.3
Hardware: PC Mac OS
: Normal normal
Target Milestone: ---
Assignee: Amy Burns
URL:
Depends on:
Blocks:
 
Reported: 2014-05-22 22:10 UTC by Jon Goldberger [MSFT]
Modified: 2015-03-09 15:55 UTC (History)
3 users (show)

Tags:
Is this bug a regression?: ---
Last known good build:


Attachments
A fix to the sample code on the recipe (24.46 KB, application/zip)
2014-06-25 18:09 UTC, John Pilczak
Details


Notice (2018-05-24): bugzilla.xamarin.com is now in read-only mode.

Please join us on Visual Studio Developer Community and in the Xamarin and Mono organizations on GitHub to continue tracking issues. Bugzilla will remain available for reference in read-only mode. We will continue to work on open Bugzilla bugs, copy them to the new locations as needed for follow-up, and add the new items under Related Links.

Our sincere thanks to everyone who has contributed on this bug tracker over the years. Thanks also for your understanding as we make these adjustments and improvements for the future.


Please create a new report on Developer Community or GitHub with your current version information, steps to reproduce, and relevant error messages or log files if you are hitting an issue that looks similar to this resolved bug and you do not yet see a matching new report.

Related Links:
Status:
RESOLVED FIXED

Description Jon Goldberger [MSFT] 2014-05-22 22:10:04 UTC
Our Android RecordVideo sample does not work out of the box. 

The problem seems to be with permissions, but adding WriteExternalStorage permissions did not resolve the issue. 

Changing this line that sets the path of the file from:

string path = Android.OS.Environment.ExternalStorageDirectory.Name + "/test.mp4";

to:

string path = Path.Combine (System.Environment.GetFolderPath (System.Environment.SpecialFolder.Personal), "test.mp4");

does allow the app to build, run, and record and playback video.
Comment 1 Jon Goldberger [MSFT] 2014-05-22 22:12:35 UTC
My version info:
=== Xamarin Studio ===

Version 5.0 (build 866)
Installation UUID: 2dc9022f-f9a8-424f-8284-bf224cbbfde0
Runtime:
	Mono 3.4.0 ((no/c3fc3ba)
	GTK+ 2.24.23 (Raleigh theme)

	Package version: 304000204

=== Apple Developer Tools ===

Xcode 5.1.1 (5085)
Build 5B1008

=== Xamarin.iOS ===

Version: 7.2.3.35 (Business Edition)
Hash: 9e24c88
Branch: 
Build date: 2014-05-12 19:42:16-0400

=== Xamarin.Android ===

Version: 4.12.4 (Business Edition)
Android SDK: /Users/apple/Library/Developer/Xamarin/android-sdk-mac_x86
	Supported Android versions:
		2.1   (API level 7)
		2.2   (API level 8)
		2.3   (API level 10)
		3.1   (API level 12)
		3.2   (API level 13)
		4.0   (API level 14)
		4.0.3 (API level 15)
		4.1   (API level 16)
		4.2   (API level 17)
		4.3   (API level 18)
		4.4   (API level 19)
Java SDK: /usr
java version "1.6.0_65"
Java(TM) SE Runtime Environment (build 1.6.0_65-b14-462-11M4609)
Java HotSpot(TM) 64-Bit Server VM (build 20.65-b04-462, mixed mode)

=== Xamarin.Mac ===

Xamarin.Mac: 1.8.0.8

=== Build Information ===

Release ID: 500000866
Git revision: 89cfcdd28a9a64d4ddc606f8c4f8e6aaafad610a
Build date: 2014-05-12 14:59:13-04
Xamarin addins: e92a35a9280dede5cbdceaaec0c40c06c163546e

=== Operating System ===

Mac OS X 10.9.3
Darwin <hostname> 13.2.0 Darwin Kernel Version 13.2.0
    Thu Apr 17 23:03:13 PDT 2014
    root:xnu-2422.100.13~1/RELEASE_X86_64 x86_64
Comment 2 Jonathan Pryor 2014-05-22 22:17:24 UTC
Those are two different paths, but that's not the important part.

The important part is the Environment documentation:

http://developer.android.com/reference/android/os/Environment.html#getExternalStorageDirectory()

> This directory may not currently be accessible if it has been mounted by the user
> on their computer, has been removed from the device, or some other problem has
> happened. You can determine its current state with getExternalStorageState().

When it fails, what is the value of Environment.ExternalStorageState? This could be an app bug, if it's attempting to write to the directory when the directory isn't writable.
Comment 3 Jon Goldberger [MSFT] 2014-05-23 13:24:11 UTC
I got the app  from here: http://docs.xamarin.com/recipes/android/media/video/record_video/

Initially  ExternalStorageDirectory.CanWrite() returned false and ExternalStorageState returned "mounted", but I had set it to be writeable, Android.OS.Environment.ExternalStorageDirectory.SetWritable(true);, and still got an error:

Java.IO.FileNotFoundException: /0/test.mp4: open failed: ENOENT (No such file or directory)
  at Android.Runtime.JNIEnv.CallVoidMethod (intptr,intptr) [0x00062] in /Users/builder/data/lanes/monodroid-mlion-monodroid-4.12-series/5e0ae404/source/monodroid/src/Mono.Android/src/Runtime/JNIEnv.g.cs:490
  at Android.Media.MediaRecorder.Prepare () [0x00043] in /Users/builder/data/lanes/monodroid-mlion-monodroid-4.12-series/5e0ae404/source/monodroid/src/Mono.Android/platforms/android-8/src/generated/Android.Media.MediaRecorder.cs:420
  at RecordVideo.Activity1/<OnCreate>c__AnonStorey0.<>m__0 (object,System.EventArgs) [0x000b2] in /Users/apple/Downloads/RecordVideo/RecordVideo/Activity1.cs:47
  at Android.Views.View/IOnClickListenerImplementor.OnClick (Android.Views.View) [0x0000d] in /Users/builder/data/lanes/monodroid-mlion-monodroid-4.12-series/5e0ae404/source/monodroid/src/Mono.Android/platforms/android-8/src/generated/Android.Views.View.cs:885
  at Android.Views.View/IOnClickListenerInvoker.n_OnClick_Landroid_view_View_ (intptr,intptr,intptr) [0x00011] in /Users/builder/data/lanes/monodroid-mlion-monodroid-4.12-series/5e0ae404/source/monodroid/src/Mono.Android/platforms/android-8/src/generated/Android.Views.View.cs:852
  at at (wrapper dynamic-method) object.948eff3c-be76-4ed5-8eff-7ca4d5eae2ae (intptr,intptr,intptr) <IL 0x00017, 0x00043>
  at --- End of managed exception stack trace ---
  at java.io.FileNotFoundException: /0/test.mp4: open failed: ENOENT (No such file or directory)
  at at libcore.io.IoBridge.open(IoBridge.java:416)
  at at java.io.FileOutputStream.<init>(FileOutputStream.java:88)
  at at java.io.FileOutputStream.<init>(FileOutputStream.java:128)
  at at java.io.FileOutputStream.<init>(FileOutputStream.java:117)
  at at android.media.MediaRecorder.prepare(MediaRecorder.java:771)
  at at mono.android.view.View_OnClickListenerImplementor.n_onClick(Native Method)
  at at mono.android.view.View_OnClickListenerImplementor.onClick(View_OnClickListenerImplementor.java:29)
  at at android.view.View.performClick(View.java:4421)
  at at android.view.View$PerformClick.run(View.java:18190)
  at at android.os.Handler.handleCallback(Handler.java:725)
  at at android.os.Handler.dispatchMessage(Handler.java:92)
  at at android.os.Looper.loop(Looper.java:175)
  at at android.app.ActivityThread.main(ActivityThread.java:5279)
  at at java.lang.reflect.Method.invokeNative(Native Method)
  at at java.lang.reflect.Method.invoke(Method.java:511)
  at at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1102)
  at at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:869)
  at at dalvik.system.NativeStart.main(Native Method)
  at Caused by: libcore.io.ErrnoException: open failed: ENOENT (No such file or directory)
  at at libcore.io.Posix.open(Native Method)
  at at libcore.io.BlockGuardOs.open(BlockGuardOs.java:110)
  at at libcore.io.IoBridge.open(IoBridge.java:400)
  at ... 17 more
Comment 4 Jonathan Pryor 2014-05-23 14:39:10 UTC
> Initially  ExternalStorageDirectory.CanWrite() returned false

Because your app can't write to external storage, because it lacks the WRITE_EXTERNAL_STORAGE permission:

http://developer.android.com/reference/android/Manifest.permission.html#WRITE_EXTERNAL_STORAGE

Please add this permission and try again.
Comment 5 Jon Goldberger [MSFT] 2014-05-23 14:51:10 UTC
Jon, sorry, yesterday when I tested this that was the first thing I checked and did, but I forgot to do it today. But don't you think that should have been added already in the sample since it write to external storage? :-)

I added the permission, verified that the directory is writeable with:
Android.OS.Environment.ExternalStorageDirectory.CanWrite()

And then get this error:
Java.IO.FileNotFoundException: /0/test.mp4: open failed: ENOENT (No such file or directory)
  at Android.Runtime.JNIEnv.CallVoidMethod (intptr,intptr) [0x00062] in /Users/builder/data/lanes/monodroid-mlion-monodroid-4.12-series/5e0ae404/source/monodroid/src/Mono.Android/src/Runtime/JNIEnv.g.cs:490
  at Android.Media.MediaRecorder.Prepare () [0x00043] in /Users/builder/data/lanes/monodroid-mlion-monodroid-4.12-series/5e0ae404/source/monodroid/src/Mono.Android/platforms/android-8/src/generated/Android.Media.MediaRecorder.cs:420
  at RecordVideo.Activity1/<OnCreate>c__AnonStorey0.<>m__0 (object,System.EventArgs) [0x000b2] in /Users/apple/Downloads/RecordVideo/RecordVideo/Activity1.cs:45
  at Android.Views.View/IOnClickListenerImplementor.OnClick (Android.Views.View) [0x0000d] in /Users/builder/data/lanes/monodroid-mlion-monodroid-4.12-series/5e0ae404/source/monodroid/src/Mono.Android/platforms/android-8/src/generated/Android.Views.View.cs:885
  at Android.Views.View/IOnClickListenerInvoker.n_OnClick_Landroid_view_View_ (intptr,intptr,intptr) [0x00011] in /Users/builder/data/lanes/monodroid-mlion-monodroid-4.12-series/5e0ae404/source/monodroid/src/Mono.Android/platforms/android-8/src/generated/Android.Views.View.cs:852
  at at (wrapper dynamic-method) object.7ac93fe5-14f6-4f83-b796-f72b8051eea5 (intptr,intptr,intptr) <IL 0x00017, 0x00043>
  at --- End of managed exception stack trace ---
  at java.io.FileNotFoundException: /0/test.mp4: open failed: ENOENT (No such file or directory)
  at at libcore.io.IoBridge.open(IoBridge.java:416)
  at at java.io.FileOutputStream.<init>(FileOutputStream.java:88)
  at at java.io.FileOutputStream.<init>(FileOutputStream.java:128)
  at at java.io.FileOutputStream.<init>(FileOutputStream.java:117)
  at at android.media.MediaRecorder.prepare(MediaRecorder.java:771)
  at at mono.android.view.View_OnClickListenerImplementor.n_onClick(Native Method)
  at at mono.android.view.View_OnClickListenerImplementor.onClick(View_OnClickListenerImplementor.java:29)
  at at android.view.View.performClick(View.java:4421)
  at at android.view.View$PerformClick.run(View.java:18190)
  at at android.os.Handler.handleCallback(Handler.java:725)
  at at android.os.Handler.dispatchMessage(Handler.java:92)
  at at android.os.Looper.loop(Looper.java:175)
  at at android.app.ActivityThread.main(ActivityThread.java:5279)
  at at java.lang.reflect.Method.invokeNative(Native Method)
  at at java.lang.reflect.Method.invoke(Method.java:511)
  at at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1102)
  at at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:869)
  at at dalvik.system.NativeStart.main(Native Method)
  at Caused by: libcore.io.ErrnoException: open failed: ENOENT (No such file or directory)
  at at libcore.io.Posix.open(Native Method)
  at at libcore.io.BlockGuardOs.open(BlockGuardOs.java:110)
  at at libcore.io.IoBridge.open(IoBridge.java:400)
  at ... 17 more
Comment 6 John Pilczak 2014-06-25 18:09:44 UTC
Created attachment 7187 [details]
A fix to the sample code on the recipe
Comment 7 John Pilczak 2014-06-25 18:12:25 UTC
Attached a fix to the sample code

The recipe code will need to be updated to these changes and the instructions should include that the user needs the WriteExternalStorage permission.

I am assigning this to Amy to update the recipe with this fix.
Comment 8 Oleg Demchenko 2015-03-05 20:20:05 UTC
@Amy could you update doc with John's fix?
Comment 9 Amy Burns 2015-03-09 15:24:39 UTC
sample updated, recipe updated.
Comment 10 Oleg Demchenko 2015-03-09 15:55:22 UTC
Thanks a bunch!