| 1 |
define([ |
| 2 |
"dojo/_base/declare", |
| 3 |
"dojo/dom-construct", |
| 4 |
"dojo/sniff", |
| 5 |
"dijit/_Contained", |
| 6 |
"dijit/_WidgetBase" |
| 7 |
], function(declare, domConstruct, has, Contained, WidgetBase){ |
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
return declare("dojox.mobile.Audio", [WidgetBase, Contained], { |
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
|
| 22 |
|
| 23 |
|
| 24 |
|
| 25 |
|
| 26 |
|
| 27 |
source: null, |
| 28 |
|
| 29 |
|
| 30 |
|
| 31 |
|
| 32 |
|
| 33 |
width: "200px", |
| 34 |
|
| 35 |
|
| 36 |
|
| 37 |
|
| 38 |
|
| 39 |
height: "15px", |
| 40 |
|
| 41 |
|
| 42 |
|
| 43 |
_playable: false, |
| 44 |
|
| 45 |
|
| 46 |
|
| 47 |
_tag: "audio", |
| 48 |
|
| 49 |
constructor: function(){ |
| 50 |
|
| 51 |
|
| 52 |
this.source = []; |
| 53 |
}, |
| 54 |
|
| 55 |
buildRendering: function(){ |
| 56 |
this.domNode = this.srcNodeRef || domConstruct.create(this._tag); |
| 57 |
}, |
| 58 |
|
| 59 |
_getEmbedRegExp: function(){ |
| 60 |
|
| 61 |
|
| 62 |
return has('ff') ? /audio\/mpeg/i : |
| 63 |
has('ie') ? /audio\/wav/i : |
| 64 |
null; |
| 65 |
}, |
| 66 |
|
| 67 |
startup: function(){ |
| 68 |
if(this._started){ return; } |
| 69 |
this.inherited(arguments); |
| 70 |
var i, len, re; |
| 71 |
if(this.domNode.canPlayType){ |
| 72 |
if(this.source.length > 0){ |
| 73 |
for(i = 0, len = this.source.length; i < len; i++){ |
| 74 |
domConstruct.create("source", {src:this.source[i].src, type:this.source[i].type}, this.domNode); |
| 75 |
this._playable = this._playable || !!this.domNode.canPlayType(this.source[i].type); |
| 76 |
} |
| 77 |
}else{ |
| 78 |
for(i = 0, len = this.domNode.childNodes.length; i < len; i++){ |
| 79 |
var n = this.domNode.childNodes[i]; |
| 80 |
if(n.nodeType === 1 && n.nodeName === "SOURCE"){ |
| 81 |
this.source.push({src:n.src, type:n.type}); |
| 82 |
this._playable = this._playable || !!this.domNode.canPlayType(n.type); |
| 83 |
} |
| 84 |
} |
| 85 |
} |
| 86 |
} |
| 87 |
has.add("mobile-embed-audio-video-support", true); |
| 88 |
if(has("mobile-embed-audio-video-support")){ |
| 89 |
if(!this._playable){ |
| 90 |
for(i = 0, len = this.source.length, re = this._getEmbedRegExp(); i < len; i++){ |
| 91 |
if(this.source[i].type.match(re)){ |
| 92 |
var node = domConstruct.create("embed", { |
| 93 |
src: this.source[0].src, |
| 94 |
type: this.source[0].type, |
| 95 |
width: this.width, |
| 96 |
height: this.height |
| 97 |
}); |
| 98 |
this.domNode.parentNode.replaceChild(node, this.domNode); |
| 99 |
this.domNode = node; |
| 100 |
this._playable = true; |
| 101 |
break; |
| 102 |
} |
| 103 |
} |
| 104 |
} |
| 105 |
} |
| 106 |
} |
| 107 |
|
| 108 |
}); |
| 109 |
}); |