Welcome!

Welcome to the official BlackBerry Support Community Forums.

This is your resource to discuss support topics with your peers, and learn from each other.

inside custom component

Web and WebWorks Development

Reply
Contributor
Posts: 28
Registered: ‎04-12-2012
My Device: Torch 9800, Playbook
My Carrier: LIME

Torch 9800 HTML audio tag problem. Please Help me

i have a webworks app that tries to play an audio file once every minute. the file is about 3 seconds long and it is played in a javascript method called by setinterval. In chrome and on the blackbgerry 9700 simulator the code runs as is expected. On my 9800 Torch device however the html audio tag acts really ridiculously. when the audio file is played sometimes i can see the audio tag has a play control and what appears to be a duration. the duration is displayed as something ridiculous -97:94:00 or something and it does count down the 3 seconds.. THEN THE FILE REPEATS. this is not what is suppose to happen. it repeats indefinitely ... however if i press the menu button over the control (that appears without me asking for it. .. i do not have the control boolean attribute anywhere) i see i have options for Repeat.. none and CurrentSong. if i choose none the mp3 stops playing

 

I am at my wits end.. can somebody please explain what is going on... following is the only snippets of code that relates to this in my app

 

 

//variables declared at the start of the script file. the only one of importance is the theaudio

var myalerts="test";

var activealerts;

var alarm=1;

var vibe=1;

var viber=1;

var alerts="dummy;";

var alarmer=-1;

var theaudio=document.createElement('audio');

var current=1;

var numalerts=1;

var ret;

 

//the only procedure where the audio is used (partial)

 

if (flag==1) {

//new alert found

if (alarm==1)

{

 

theaudio.src="alarm.mp3";

//theaudio.volume=0.3;

theaudio.play();

 

//lets do the home indicator

try{

numi=parseInt(numalerts);

blackberry.app.showBannerIndicator("bannericon.png",numi);

}

catch(e){

//alert(e);

}

}

 

now before anyone asks i have the config.xml set up correctly and the code works PERFECTLY on a 9700 simulator and chrome... its only the 9800 on os 6.0.0.723 that has the problem. Please advise if this is a known issue or how to solve it.

 

Thank you

Contributor
Posts: 28
Registered: ‎04-12-2012
My Device: Torch 9800, Playbook
My Carrier: LIME

Re: Torch 9800 HTML audio tag problem. Please Help me

Hi

 

I dont remember the name of the developer that replied to me in the other thread but i have some further information.  I can confirm the HTML5 audio tag works perfectly and therefore my app works perfectly on my girlfriend's Torch 9800 and she is running the EXACT same OS 6.0.0.723 as I am. I am completely confused by this. I can confirm the erratic behavior even happens on the Torch 6.0.0.709 Simulator. So either my girlfriend has the only working Torch or something is seriously wrong.

 

Hope this helps somehow

Highlighted
Retired
Posts: 1,561
Registered: ‎04-12-2010
My Device: BlackBerry Z10
My Carrier: Bell

Re: Torch 9800 HTML audio tag problem. Please Help me

Hi there,

 

I've been doing some testing to attempt reproducing the issue you've noted. I set up a page with three sections:



Untitled.png

(Note: Screenshot from Chrome.)

 

The top section creates an audio element programmatically. You can then use the play/pause button to play the audio. You can also use the reset button to set the current play time back to 0. I did not set up any listeners there, so when the audio finishes, you will need to pause then play again to restart the track.

 

The second section links directly to the audio file and provides default controls.

 

The third section links to the audio file, but is in a setTimeout loop; initiated once the DOM is ready. Turning repeat off will invoke clearTimeout to stop the repetition. Turning repeat back on will resume the playback via additional setTimeout calls.

 

On the PlayBook and my desktop browsesr, the above worked just fine.

 

On my 9800 running 6.0.0.723 I saw the following results:

 

  • On load, the setTimeout implementation started playing automatically. It could be turned off through the control, and then turned back on without issue.

 

  • The top controls worked as expected in that after the control was created, I could then play/pause/replay the track. The only part that failed was explicitly reseting the track via the reset function. I would need to explore further as to why though.

 

  • The first graphical control / middle section successfully controlled the audio track as expected.

 

Basically, I could not produce any issues in the playback of my sample audio track. For reference, the code I used is as follows:

 

<!DOCTYPE html>
<html>
	<body>
		<div>
			<a href="#" onclick="create(this); return false;">create</a>&nbsp;
			<a href="#" onclick="play(this); return false;">play</a>&nbsp;
			<a href="#" onclick="reset(this); return false;">reset</a>&nbsp;
			<br />
			<br />
			<audio src="drums.mp3" controls></audio>
			<br />
			<br />
			<a href="#" onclick="repeat(this); return false;">repeat on</a>&nbsp;
			<br />
			<audio id="repeat" src="drums.mp3" controls></audio>
		</div>
		<br />
		<div id="log"></div>
	
		<script type="text/javascript">
			var audio = null;
			var playing = false;
			
	
			function log(text) {
				var div = document.createElement("div");
				div.innerHTML = text;
				document.querySelector("#log").appendChild(div);
			}
	
			function create(_this) {
				try {
					audio = document.createElement("audio");
					audio.src="drums.mp3";
					log("audio created.");
				} catch (err) {
					log("create: " + err);
				}
			}
			
			function play(_this) {
				try {
					if (playing) {
						audio.pause();
						playing = false;
						_this.innerHTML = "play";
						log("audio paused.");
					} else {
						audio.play();
						playing = true;
						_this.innerHTML = "pause";
						log("audio started.");
					}
				} catch (err) {
					log("play: " + err);
				}
			}
			
			function reset(_this) {
				try {
					audio.currentTime = 0;
					log("audio reset.");
				} catch (err) {
					log("reset: " + err);
				}
			}

			var repeater;
			var repeating = true;
			function repeat(_this) {
				try {
					if (repeating) {
						clearTimeout(repeater);
						_this.innerHTML = "repeat off";
						repeating = false;
					} else {
						ready();
						_this.innerHTML = "repeat on";
						repeating = true;
					}
				} catch (err) {
					log("repeat: " + err);
				}
			}

			function ready() {
				repeater = setTimeout("ready();", 4000);
				document.querySelector("#repeat").play();
			}
			window.addEventListener("DOMContentLoaded", ready, false);
		</script>
	</body>
</html>

As you can see, just a handful of controls and JavaScript methods to provide the associated functionality. Could you give the above a shot and let me know how it compares to the behaviour you see with your application?

 

Erik Oros

BlackBerry Development Advisor


Erik Oros | @WaterlooErik | eoros@blackberry.com | Developer Issue Tracker

If a reply has answered your question, please click Accept as Solution to help other visitors in the future.
Contributor
Posts: 28
Registered: ‎04-12-2012
My Device: Torch 9800, Playbook
My Carrier: LIME

Re: Torch 9800 HTML audio tag problem. Please Help me

I have not tested it yet as i am not home but i just realised something. In my music player media app i have my repeat options set to Current Song is exactly what i see when i use the <audio> tag on my phone! My girlfriend has her repeat turned to off. i believe that is the issue. if you would put your repeat on to Current Song in your media player i believe the same would happen to you.

This behaviour is not what is supposed to happen so i have to consider it a bug. my HTML5 audio tag behavior should not depend on the repeat option in my media player.

what i need is for you to try the first one that is done programatically with no controls. See if you can change the repeat option for that one as you will note i dont want any controls showing in my code.

awaiting your feedback and thank you for your efforts
Retired
Posts: 1,561
Registered: ‎04-12-2010
My Device: BlackBerry Z10
My Carrier: Bell

Re: Torch 9800 HTML audio tag problem. Please Help me

Hi there, 

 

If this does end up being confirmed as the cause, I would agree that this should be considered a bug and an Issue Tracker case should be logged.

 

I haven't had a chance to test this one out yet (I'm currently in Toronto for the FITC conference and don't have access to my usual development tools.) But I will test this out as soon as I am able (Thursday at the latest.)

 

Regards,

 

Erik Oros

BlackBerry Development Advisor


Erik Oros | @WaterlooErik | eoros@blackberry.com | Developer Issue Tracker

If a reply has answered your question, please click Accept as Solution to help other visitors in the future.
Retired
Posts: 1,561
Registered: ‎04-12-2010
My Device: BlackBerry Z10
My Carrier: Bell

Re: Torch 9800 HTML audio tag problem. Please Help me

Hello again,

 

So I've had a chance to try this out on my devices and to me it doesn't seem that the repeat option in the media player is affecting the playback of the browser.

 

I leveraged audio.loop = null and audio.loop = "loop" to toggle the repeat of my controls, and it seems to be working as would be expected.

 

If your girlfriend does turn on repeat in her media player, does she then see the same behaviour you see on your device?

 

Erik Oros

BlackBerry Development Advisor


Erik Oros | @WaterlooErik | eoros@blackberry.com | Developer Issue Tracker

If a reply has answered your question, please click Accept as Solution to help other visitors in the future.
Contributor
Posts: 28
Registered: ‎04-12-2012
My Device: Torch 9800, Playbook
My Carrier: LIME

Re: Torch 9800 HTML audio tag problem. Please Help me

Right now im not sure she has the app on her phone. i can certainly tell you that taking off the Repeat current Song on the media player fixed the problem on my phone. My app no longer loops audio. so the issue exists. One other thing, i see you mentioned loop=null; is that valid code?? can i use audio.loop=null to turn off looping?

 

 

Retired
Posts: 1,561
Registered: ‎04-12-2010
My Device: BlackBerry Z10
My Carrier: Bell

Re: Torch 9800 HTML audio tag problem. Please Help me

[ Edited ]

Sorry, setting it to null is not what we want to do here. We want to remove the attribute completely:

http://www.w3schools.com/dom/met_element_removeattribute.asp

 

Good catch.

 

Erik Oros

BlackBerry Development Advisor


Erik Oros | @WaterlooErik | eoros@blackberry.com | Developer Issue Tracker

If a reply has answered your question, please click Accept as Solution to help other visitors in the future.
Contributor
Posts: 28
Registered: ‎04-12-2012
My Device: Torch 9800, Playbook
My Carrier: LIME

Re: Torch 9800 HTML audio tag problem. Please Help me

[ Edited ]

Erik,

 

thank you so much for all your help so far but the issue count continues to grow. As far as i can tell my application is very simple and i cannnot figure out why i am getting all these issues. The issue with Repeat still persists and now i get an issue where the orientation attribute is being ignore. The app would start with the landscape orientation as specified by the config.xml file <rimSmiley Surprisedrientation="landscape"> but when an alert comes in (when the audio file is to be played) the orientation lock stops working. I can only assume its something once again with the audio tag.

 

i would like to send you my complete code and so you can convince yourself that this project should work. Maybe if you see the code and actually run the code you can figure out whats the deal. Quick synopsis of the code... it simply fetches an html file from a server and depending on the value of some hidden fields determines if to play the audio file (alarm) or not. There is a little database code to save user preferences and thats basically.

 

my email address is (personal info removed)@hotmail.com

 

if u desire send me a note there so i can send you everything i have. Maybe you can figure out whats going on because i am at my wits end.

 

thank you

Contributor
Posts: 28
Registered: ‎04-12-2012
My Device: Torch 9800, Playbook
My Carrier: LIME

Re: Torch 9800 HTML audio tag problem. Please Help me

One further note, something is definitely weird with my phone because if i press the mute button at the top of the phone my alarm sound plays! just like when you press it to pause and unpause the music player. This clearly points to the audio tag activating and using the mediaplayer on my torch. In fact the media player is probably what is also causing me to lose my orientation lock as its probably attaching itself to the screen and changing the dimensions of my app. (im not sure about that last part but i do believe it has to be related.) I don't understand why your torch isnt experiencing the same behaviour as min