Permalink
Browse files

Added the media section, allowing to record and playback sounds

  • Loading branch information...
1 parent 4e6985d commit c28f3a36427cdb9c35cefb140b12a51933e1ace3 Adrian Kosmaczewski committed Apr 2, 2012
Showing with 71 additions and 3 deletions.
  1. +4 −2 index.html
  2. +67 −1 js/app.js
View
@@ -28,7 +28,7 @@
<!--<li><a href="#events">Events</a></li>-->
<!--<li><a href="#file">File</a></li>-->
<li><a href="#geolocation">Geolocation</a></li>
- <!--<li><a href="#media">Media</a></li>-->
+ <li><a href="#media">Media</a></li>
<li><a href="#notification">Notification</a></li>
<!--<li><a href="#storage">Storage</a></li>-->
</ul>
@@ -229,7 +229,9 @@
<h1>Media</h1>
</div>
<div data-role="content">
-
+ <a data-role="button" id="recordButton">Record</a>
+ <a data-role="button" id="stopButton">Stop</a>
+ <a data-role="button" id="playButton">Play</a>
</div>
<div data-role="footer" data-position="fixed">
<h4>&copy; http://mobile-training.ch</h4>
View
@@ -424,8 +424,74 @@ function onDeviceReady() {
list.listview('refresh');
}, null, options);
- }).live('pagehide', function (event) {
+ });
+
+ $("#media").live('pageinit', function (event) {
+ var soundFile = null;
+ var recording = false;
+ function failure(error) {
+ console.log('error: ' + error.code + ', message: ' + error.message);
+ }
+ function success() {
+ console.log('media ready - success');
+ $('#recordButton').show();
+ $('#stopButton').hide();
+ $('#playButton').show();
+ }
+
+ $('#recordButton').hide();
+ $('#stopButton').hide();
+ $('#playButton').hide();
+ console.log('onclick');
+ var path = 'recording.wav';
+ window.requestFileSystem(LocalFileSystem.PERSISTENT, 0, function (fileSystem) {
+ console.log('file system requested');
+ fileSystem.root.getFile(path, {create: true}, function (fileEntry) {
+ console.log('file got');
+ soundFile = new Media(fileEntry.fullPath, success, failure);
+ $('#recordButton').show();
+ }, failure);
+ }, failure);
+
+ $("#recordButton").on('click', function (event) {
+ if (soundFile) {
+ $('#recordButton').hide();
+ $('#stopButton').show();
+ $('#playButton').hide();
+ recording = true;
+ soundFile.startRecord();
+ console.log('recording started');
+ }
+ });
+
+ $('#stopButton').on('click', function (event) {
+ if (soundFile) {
+ $('#recordButton').show();
+ $('#stopButton').hide();
+ $('#playButton').show();
+ if (recording) {
+ soundFile.stopRecord();
+ console.log('recording stopped');
+ recording = false;
+ }
+ else {
+ soundFile.stop();
+ console.log('playback stopped');
+ }
+ }
+ });
+
+ $('#playButton').on('click', function (event) {
+ if (soundFile) {
+ $('#recordButton').hide();
+ $('#stopButton').show();
+ $('#playButton').hide();
+ recording = false;
+ soundFile.play();
+ console.log('file playing');
+ }
+ });
});
}

0 comments on commit c28f3a3

Please sign in to comment.