Titanium.Media.AudioPlayer:我不能将“Change”事件处理程序与“Progress”事件处理程序一起使用吗?

时间:2015-12-12 22:13:57

标签: javascript titanium titanium-mobile

var player = Titanium.Media.createAudioPlayer({
    url : '101.mp3',
    allowBackground : false
});

var eventHandler = function(e) {
    Ti.API.info("Handler:" + JSON.stringify(e, null, 4));
};

Ti.API.info("Setting up event handlers");
player.addEventListener('progress', eventHandler);
// player.addEventListener('change', eventHandler);

Ti.API.info("Starting player...");
player.play();

结果是:

[INFO] :   Setting up event handlers
[INFO] :   Starting player...
[INFO] :   Handler:{
[INFO] :       "progress": 927.4149659863946,
[INFO] :       "bubbles": true,
[INFO] :       "type": "progress",
[INFO] :       "source": {},
[INFO] :       "cancelBubble": false
[INFO] :   }  
[INFO] :   Handler:{
[INFO] :       "progress": 1926.984126984127,
[INFO] :       "bubbles": true,
[INFO] :       "type": "progress",  
[INFO] :       "source": {},
[INFO] :       "cancelBubble": false
[INFO] :   }
[INFO] :   Handler:{
[INFO] :       "progress": 2924.9206349206347,
[INFO] :       "bubbles": true,
[INFO] :       "type": "progress",
[INFO] :       "source": {},
[INFO] :       "cancelBubble": false
[INFO] :   }
[INFO] :   Handler:{
[INFO] :       "progress": 3926.7346938775513,
[INFO] :       "bubbles": true,
[INFO] :       "type": "progress",
[INFO] :       "source": {},
[INFO] :       "cancelBubble": false
[INFO] :   }

所以,显然我得到了“进步”事件......

现在,如果我取消注释第二个addEventListener调用:

player.addEventListener('progress', eventHandler);
player.addEventListener('change', eventHandler);

我明白了:

[INFO] :   Setting up event handlers
[INFO] :   Starting player...
[INFO] :   Handler:{
[INFO] :       "state": 1,
[INFO] :       "description": "starting",
[INFO] :       "bubbles": true,
[INFO] :       "type": "change",
[INFO] :       "source": {},
[INFO] :       "cancelBubble": false
[INFO] :   }
[INFO] :   Handler:{
[INFO] :       "state": 2,
[INFO] :       "description": "waiting_for_data",
[INFO] :       "bubbles": true,
[INFO] :       "type": "change",
[INFO] :       "source": {},
[INFO] :       "cancelBubble": false
[INFO] :   }
[INFO] :   Handler:{
[INFO] :       "state": 3,
[INFO] :       "description": "waiting_for_queue",
[INFO] :       "bubbles": true,
[INFO] :       "type": "change",
[INFO] :       "source": {},
[INFO] :       "cancelBubble": false
[INFO] :   }
[INFO] :   Handler:{
[INFO] :       "state": 4,
[INFO] :       "description": "playing",
[INFO] :       "bubbles": true,
[INFO] :       "type": "change",
[INFO] :       "source": {},
[INFO] :       "cancelBubble": false
[INFO] :   }

没有更多“进步”事件?

任何人都能解释一下吗?

2 个答案:

答案 0 :(得分:0)

定义两个事件处理程序并为每个事件添加一个。 通常,您处理音频进度事件和更改事件的方式也非常不同。

   var onProgressHandler = function(e) {
        Ti.API.info("Progress Handler:" + JSON.stringify(e, null, 4));
    };

    var onChangeHandler = function(e) {
        Ti.API.info("Change Handler:" + JSON.stringify(e, null, 4));
    };

    Ti.API.info("Setting up event handlers");
    player.addEventListener('progress', onProgressHandler);
    player.addEventListener('change', onChangeHandler);

答案 1 :(得分:0)

虽然AudioPlayer和一个Window或任何其他视图共享相同的code来管理侦听器,但我无法通过以下方式重现:

win = Ti.UI.createWindow();
win.addEventListener('singletap', listen);
win.addEventListener('doubletap', listen);
win.addEventListener('longpress', listen);
function listen(e) {
  console.log(e.type);
}
win.open();

但是,由于您看起来具有良好的可重现用例,请创建一个JIRA票证,以便我们解决此问题。