Quantcast
Channel: Appcelerator Developer Center Q&A Unanswered Questions 20
Viewing all articles
Browse latest Browse all 8068

Cannot set URL after the fact on Ti.Media.createSound()

$
0
0

I can successfully play a remote mp3 via the Titanium.Media.Sound object, but there is a problem. The 1st clip always plays fine. But each time I try to play a different clip, the first clip plays again. This is 100% repeatable.

So at the top of my js file I'm doing this:

var soundPlayer = Ti.Media.createSound({allowBackground: false});

Then inside the event listener for a button click, I'm setting the URL thusly:

soundPlayer.setUrl(mp3URL);

And I have even tried this approach:

soundPlayer.url = mp3URL;

But they both have the same flaw: the audio is always still the first clip, never any clip I set afterward. I have verified via console logging that in fact a new url was handed to the sound player, and in fact the new url points at a valid mp3. It seems that once I set a url for the sound player, it is set in stone and cannot be changed--just replayed.

So then I tried a completely different approach. Inside my button click listener, I re-create the Sound object each time and hand in the new URL:

soundPlayer = Ti.Media.createSound({allowBackground: false, url: mp3URL});

This actual DOES work and plays the new url each time, BUT it has a terrible side effect: any attached event listeners no longer fire. I need to track state changes in the player, for example when it completes, etc. But these event listeners no longer fire when I take this approach.

Strangely, the AudioPlayer object behaves correctly in all respects, allows me to set new URLs, etc. BUT the problem with that is that AudioPlayer absolutely refuses to play any mp3 file smaller than 40Kb. I have posted questions around that issue on this and other forums, and based on responses and experimentation, I have lots of evidence for the 40Kb limitation, and no evidence to the contrary.

So why can't I change the url after object creation on the Sound object? Thanks in advance for any ideas.


Viewing all articles
Browse latest Browse all 8068

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>