music播放音乐和system中播放控制栏的关联
来源:互联网 发布:淘宝账号怎么多个账号 编辑:程序博客网 时间:2024/06/05 11:13
主要用到了IAC 通讯机制
http://tech.mozilla.com.tw/posts/3560/inter-app-communication-app-%E7%9A%84%E6%BA%9D%E9%80%9A%E6%A9%8B%E6%A8%91
在music界面第一页是Tile形式,点击某一首进行播放的click事件在,注意:不能在nightly中同时打两个异步的断点,如下面的1,2,3需要各自单独打断点:music.js
init: function tv_init() { this.dataSource = []; this.index = 0; this.view.addEventListener('click', this); this.view.addEventListener('input', this); this.view.addEventListener('touchend', this); this.searchInput.addEventListener('focus', this); },handleEvent: function tv_handleEvent(evt) { function tv_resetSearch(self) { evt.preventDefault(); self.searchInput.value = ''; SearchView.clearSearch(); } var target = evt.target; if (!target) return; switch (evt.type) { case 'touchend': //1,先响应此case // Check for tap on parent form element with event origin as clear buton // This is workaround for a bug in input_areas BB. See Bug 920770 if (target.id === 'views-tiles-search') { var id = evt.originalTarget.id; if (id && id !== 'views-tiles-search-input' && id !== 'views-tiles-search-close') { tv_resetSearch(this); return; } } if (target.id === 'views-tiles-search-clear') { tv_resetSearch(this); return; } break; case 'click': //2,后响应click if (target.id === 'views-tiles-search-close') { if (ModeManager.currentMode === MODE_SEARCH_FROM_TILES) { ModeManager.pop(); } this.hideSearch(); evt.preventDefault(); } else if (target.dataset.index) { var handler; var index = target.dataset.index; var data = this.dataSource[index]; handler = tv_playAlbum.bind(this, data, index); //这里有个handler target.addEventListener('transitionend', handler); } break; case 'focus': if (target.id === 'views-tiles-search-input') { if (ModeManager.currentMode !== MODE_SEARCH_FROM_TILES) { ModeManager.push(MODE_SEARCH_FROM_TILES); SearchView.search(target.value); } } break; case 'input': if (target.id === 'views-tiles-search-input') { SearchView.search(target.value); } break; default: return; } function tv_playAlbum(data, index) { //3,对应上面的handler处理,此函数中播放音乐 var key = 'metadata.album'; var range = IDBKeyRange.only(data.metadata.album); var direction = 'next'; ModeManager.push(MODE_PLAYER, function() { PlayerView.clean(); // When an user tap an album on the tilesView // we have to get all the song data first // because the shuffle option might be ON // and we have create shuffled list and play in shuffle order playerHandle = musicdb.enumerateAll(key, range, direction, function tv_enumerateAll(dataArray) { PlayerView.setSourceType(TYPE_LIST); PlayerView.dataSource = dataArray; if (PlayerView.shuffleOption) { PlayerView.setShuffle(true); PlayerView.play(PlayerView.shuffledList[0]); } else { PlayerView.play(0); } } ); }); target.removeEventListener('transitionend', handler); } }};
music中communications.js中有:
this.mrc = new MediaRemoteControls();
music:MediaRemoteControls?在中shared目录下的remote_controls.js中,该类中会有_postMessage的动作以和system交互。
MediaRemoteControls.prototype.notifyAppInfo = function(info) { // Send the app info via IAC. this._postMessage('appinfo', info); //system中处理的一种};...// Now, send it via IAC. this._postMessage('nowplaying', metadata); //system中处理的一种...// Now, send it via IAC.this._postMessage('status', status); //system中处理的一种...MediaRemoteControls.prototype._postMessage = function(name, value) { var message = {type: name, data: value}; if (!this._ports) { if (this._queuedMessages) this._queuedMessages.push(message); } else { this._ports.forEach(function(port) { port.postMessage(message); }); }};
在system的manifest.webapps中有:
"connections": { "mediacomms": { "description": "Communication with media apps for now playing info", "rules": {} }, "ftucomms": { "description": "Communicate between communications/ftu and System", "rules": {} }, "bluetoothTransfercomms": { "description": "Communication with bluetooth apps for sending files info", "rules": {} }
system中用到shared目录下的iac_handler.js中有,在这里会给mediacomms加上前缀iac-
var IACHandler = { _eventPrefix: 'iac-', _ports: {}, init: function onInit() { var self = this; window.navigator.mozSetMessageHandler('connection', function onConnected(request) { ... var evtName = self._eventPrefix + keyword; var iacEvt = document.createEvent('CustomEvent'); iacEvt.initCustomEvent(evtName, /* canBubble: */ true, /* cancelable */ false, message); window.dispatchEvent(iacEvt); ...
system下lockscreen.js及notification.js中的播放控制器均是media_playback.js中MediaPlaybackWidget的对象,这里会进一步处理经过IACHandler处理过的message
window.addEventListener('iac-mediacomms', this.handleMessage.bind(this)); ... MediaPlaybackWidget.prototype = { handleMessage: function mpw_handleMessage(event) { var message = event.detail; switch (message.type) { case 'appinfo': this.updateAppInfo(message.data); break; case 'nowplaying': this.updateNowPlaying(message.data); break; case 'status': this.updatePlaybackStatus(message.data); break; } }, ...
0 0
- music播放音乐和system中播放控制栏的关联
- iOS音乐播放器的后台播放和远程控制
- 播放音乐:pygame.mixer.music
- Service后台服务控制音乐的播放暂停和停止,播放完自动播放下一曲
- Android中通过耳机按键控制音乐播放的实现
- HTML5 Audio中控制音乐暂停、播放的js
- Android音乐编程:控制应用程序的音量和播放
- Android音乐编程:控制应用程序的音量和播放
- android源码解析------Music 音乐播放器
- 源码 Music音乐播放器代码结构
- Android实现音乐播放 Music 详解
- 控制MediaPlayer播放音乐
- 音乐播放暂停控制
- 在当前应用的Activity 中如何对正在播放的music 进行控制
- 在当前应用的Activity 中如何对正在播放的music 进行控制
- android music暂停或停止其他音乐播放器的播放
- 只能通过语音控制的概念型音乐播放器乐流Music Flow:想要带给用户最原始的交互体验,说出你想听的音乐
- Button的使用(十四):控制音乐播放
- Android 4.0 中由ProGuard引发的一场血案
- C++高性能服务框架revover:rudp总体介绍(可靠UDP传输)
- 排序算法:选择排序
- 【不到最后,不要轻易下判断】
- npm安装错误解决方法 at Object.parse (native) 镜像
- music播放音乐和system中播放控制栏的关联
- eclipse新建project
- 测试ubuntu安装sphinx及配置集成到magento产品搜索
- live555 学习笔记
- 关于“using namespace std”的一些文章
- stm32 外部中断嵌套[操作寄存器+库函数]
- Winform-程序员表白程序
- 修改JAR中的配置文件
- myeclipse web工程前面有一个大感叹号