Android: recording a video of your application

As I am releasing a new application any day now (Kludd) I was in need to record some gameplay from the app in order to do some kind of video promo. I had no idea how to record from a telephone (I knew how to take screenshots on my Samsung Galaxy S4 which was by holding down the on/off-button and the home button simultaneously) so I googled it.
I found that you could do it using your Android SDK. These are the steps in short:

* Connect your android phone to your computer
* In a command prompt, step into your android sdk directory and then platform-tools directory
* Enter the following command: adb shell screenrecord /sdcard/FILENAME.mp4 (cancel/end the recording by pressing CTRL + C)

(don't mind the errors, the recording still works!)
(don’t mind the errors, the recording still works!)

 

After that either go in on the phone via your computer explorer and enter /Phone/ and you’ll find the video there or find it using whatever exploration app you want on the phone.

PhoneGap: Attempt to call getDuration without a valid mediaplayer

I use phone-gap to handle the gap between HTML 5 and Android and I’ve been very pleased with the framework thus far. Today, however, I had a very annoying issue with the Media-object found in PhoneGap. I got the following error:

10-27 20:02:14.039: E/MediaPlayer(16984): error (-19, 0)
10-27 20:02:14.039: V/MediaPlayer(16984): callback application
10-27 20:02:14.039: V/MediaPlayer(16984): back from callback
10-27 20:02:14.039: V/MediaPlayer(16984): getDuration_l
10-27 20:02:14.039: E/MediaPlayer(16984): Attempt to call getDuration without a valid mediaplayer
10-27 20:02:14.039: V/MediaPlayer(16984): message received msg=100, ext1=-38, ext2=0
10-27 20:02:14.039: E/MediaPlayer(16984): error (-38, 0)

The Attempt to call getDuration without a valid mediaplayer part of the error seemed to be the most usable and I googled it. It turned out that android can only run a finite amount of sound instances. From the PhoneGap documentation:

Function media.release is a synchronous function that releases the underlying operating systems audio resources. This function is particularly important for Android as there are a finite amount of OpenCore instances for media playback. Developers should call the ‘release’ function when they no longer need the Media resource.

So, I added release() to my code, like this:

var change = new Media("change.wav");
change.setVolume = GlobalSettings.EffectVolume;
change.play();
change.release();

And, instead I got the following error in my catalog:

10-27 20:10:26.049: D/AudioPlayer(21033): renaming /storage/emulated/0/tmprecording.3gp to change.wav
10-27 20:10:26.049: E/AudioPlayer(21033): FAILED renaming /storage/emulated/0/tmprecording.3gp to change.wav

The problem seemed to be that the file wasn’t finished playing (obviously) so it crashed. I then tested to place the release after the sound had finished playing:

var change = new Media("/android_asset/www/sound/effects/Change.wav", function()
{
	this.release();
});
change.setVolume = GlobalSettings.EffectVolume;
change.play();

This has worked well and has caused no crashes. The second, optional, parameter of the Media object takes a callback that will be called when the sound has finished playing.

Android error: Error generating final archive: java.io.FileNotFoundException: C:\[PATH]\resources.ap_ does not exist TestingAndroid

I got this annoying error now when trying to run my application:


Error generating final archive: java.io.FileNotFoundException: C:\Users\maffelu\workspace\TestingAndroid\bin\resources.ap_ does not exist

There were several solutions available on google:

  • Do a clean (didn’t work for me)
  • Restart eclipse (the windows way didn’t work either)
  • Create a new resources.ap_ file in the directory specified in the error message (this did work for me, wohoo!)
  • Reinstall the Android SDK (thankfully it didn’t go this far…)

Feel free to try all solutions until it gets fixed 😛

Android error: Error generating final archive: Debug Certificate expired on [xxx]

I got this error when I tried to start my android application:


Error generating final archive: Debug Certificate expired on 2012-01-14 21:26 TestingAndroid Unknown Android Packaging Problem

I hadn’t been androiding for a while and I’d never seen this before. Luckily google could help me on this one, but I’ll put the solution here anyway:

  1. Go to %USERPROFILE%/.android
  2. Delete the debug.keystore file there
  3. Clean your project and rebuild
  4. Done!

The error should be gone now!