Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function SoundController() {
- var hasSound = false;
- function callMP3PlayerMethod(methodName, args) {
- var result = null;
- try {
- if (app.mp3playerIsInit) {
- if (!args) {
- args = [];
- }
- result = mp3player[methodName].apply(mp3player, args);
- }
- }
- catch (e) {
- try {
- GA("Radio", "SWFError", e.message + "[" + methodName, "; " + util.cloneArray(args).join(",") + "]");
- }
- catch (e) {
- GA("Radio", "SWFError", "CallMethod:" + methodName);
- }
- }
- return result;
- }
- this._play = function (url, posAsMillis) {
- hasSound = true;
- callMP3PlayerMethod("playMusic", [url, posAsMillis]);
- };
- this.closeMusicStream = function () {
- if(hasSound){
- clearInterval(updateInterval);
- callMP3PlayerMethod("closeMusicStream");
- hasSound = false;
- }
- };
- this.setVolume = function (vol) {
- if(hasSound) {
- callMP3PlayerMethod("setMusicVolume", [vol / 100]);
- }
- };
- var updateInterval;
- this.playSoundEffect = function (url, volume) {
- callMP3PlayerMethod("setSoundEffectVolume",[volume/100]);
- callMP3PlayerMethod("playSoundEffect",[url]);
- };
- this.playSound = function (opts) {
- clearInterval(updateInterval);
- var onError = function () {
- hasSound = false;
- clearInterval(updateInterval);
- if (opts.onError) {
- opts.onError();
- }
- };
- var onComplete = function () {
- hasSound = false;
- clearInterval(updateInterval);
- if (opts.onComplete) {
- opts.onComplete();
- }
- };
- window.onMP3PlayerErrorListener = onError;
- window.onMP3PlayerCompleteListener = onComplete;
- var volume = util.isDef(opts.volume) ? opts.volume : 100;
- var position = opts.position || 0;
- this._play(opts.url, position);
- this.setVolume(volume);
- if (opts.onUpdate) {
- updateInterval = setInterval(function () {
- var info = callMP3PlayerMethod("getMusicInfo");
- if (info) {
- opts.onUpdate(info.position);
- }
- }, 1000);
- opts.onUpdate(position);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement