You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@cordova.apache.org by "Shazron Abdullah (JIRA)" <ji...@apache.org> on 2012/10/20 01:50:12 UTC

[jira] [Resolved] (CB-1680) Uncaught TypeError in cordova-*.js when using media API

     [ https://issues.apache.org/jira/browse/CB-1680?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Shazron Abdullah resolved CB-1680.
----------------------------------

    Resolution: Invalid

Ripple issue - it has been filed here: https://github.com/blackberry/Ripple-UI/issues/597
                
> Uncaught TypeError in cordova-*.js when using media API
> -------------------------------------------------------
>
>                 Key: CB-1680
>                 URL: https://issues.apache.org/jira/browse/CB-1680
>             Project: Apache Cordova
>          Issue Type: Bug
>          Components: CordovaJS
>    Affects Versions: 2.0.0
>         Environment: 1. Ripple, Chrome, Mac OSX 10.7.5
> 2. Phonegap Build, Apple iPad
>            Reporter: Per Quested Aronsson
>            Assignee: Filip Maj
>              Labels: javascript, ripple
>             Fix For: Master
>
>   Original Estimate: 24h
>  Remaining Estimate: 24h
>
> When testing my code in Ripple, I get the following error and no sound plays:
> {code}
> Uncaught TypeError: Cannot set property '_duration' of undefined cordova-2.0.0.js:3090
> Media.onStatus cordova-2.0.0.js:3090
> (called from anonymous function) ripple.js:477
> row 3090: media._duration = value;
> {code}
> The same code tested in Phonegap Build does *not* crash. It doesn't work as expected, but it doesn't crash. Audio playback doesn't stop when it should. The audio file is played to the end every time.
> Please find the relevant part of the code below. It will not run as is. It expects to find an audio file of at least 8s duration at "audio/FX.m4a", and it expects to find an HTML element with ID "cross", but that's it I think.
> {code:javascript}
>     function AudioPG() {
> 		var self = this; 
> 		var soundOff = false;
> 		var inter;
> 		var sound = new Media('audio/FX.m4a', self.onSuccess, self.onError);
> 		var segmentEnd = 0.5; //sound.getDuration(); // used for sound
> 		var sprites = { // id: [start, length], startpoints: 0,1,2,7
> 			0: [1, 1.7], // Jackpot
> 			1: [0.0, 0.5], // Click
> 			2: [2.5, 5], // Whosh
> 			3: [7.2, 7.7] // Buzz
>         };
>         
> 		this.checkSprite = function () { console.log('checkSprite');
> 			if (segmentEnd) {
>                 sound.getCurrentPosition(function(position) { console.log([position, segmentEnd]);
>                     if (position >= segmentEnd) { // getCurrentPosistion uses seconds
>                         sound.pause();
>                         clearInterval(inter);
>                         inter = null;
>                     }
>                },
>                 function(e) {
>                     console.log("Error getting pos=" + e);
>                 }
>               );
> 			}
> 			
> 		};
> 	
> 		this.playSprite = function (id) {
> 			if (soundOff) {
> 				return;
> 			}
> 			var startTime = sprites[id][0];
> 			segmentEnd = startTime + sprites[id][1];
> 			if (sound) {
> 				sound.seekTo(startTime*1000); // seekTo uses milliseconds
> 				sound.play();
> 				if (!inter) {
> 					inter = setInterval(self.checkSprite,100);	
> 				}
> 				
> 			}
> 			
> 		};
> 	
> 		this.stopSprite = function () {
> 			if (sound) {
> 				sound.pause();
> 			}
> 		};
> 	
> 		this.toggleSound = function (e) {
> 			var cross = e.target;
> 			soundOff = !soundOff;
> 			cross.style.opacity = (soundOff ? 0.4 : 0);
> 		};
> 		
> 		// onSuccess Callback
>         //
>         this.onSuccess = function () {
>             console.log("playAudio():Audio Success");
>         };
>         // onError Callback 
>         //
>         this.onError = function (error) {
>             alert('code: '    + error.code    + '\n' + 
>                   'message: ' + error.message + '\n');
>         };
> 			
> 		document.getElementById('cross').addEventListener('touchstart', self.toggleSound, false);
> 		console.log(['AudioPG', segmentEnd]);
>     }
> {code}

--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators
For more information on JIRA, see: http://www.atlassian.com/software/jira