teaching machines

CS 491 Lecture 18 – Cordova

November 15, 2012 by . Filed under cs491 mobile, fall 2012, lectures.

Before class

A

Before next class:

B

Before next class:

In class

Create a Cordova plugin that plays the RTTTL file. Your jQuery/jQuery Mobile-powered code can be dropped in assets/www in a Cordova project. A blank project named cordova_blank.zip is available on the class folder on the W: drive. You can make your own with the Cordova tools, but the process is annoying.

Android’s MediaPlayer knows about RTTTL, but it has to be stored in a file before it can be played. Assuming you have the RTTTL as a String, it can be played with the following code:

FileOutputStream out = context.openFileOutput("song.rtttl", Context.MODE_WORLD_READABLE);
out.write(rtttl.getBytes());
out.close();

Uri uri = Uri.fromFile(new File(context.getFilesDir(), "song.rtttl"));
MediaPlayer player = MediaPlayer.create(context, uri);
player.start();

Fun!