[Type] Audio
Part of: mobl::media
Inherits from: mobl::Object
Audio
represents an audio file. Note, currently HTML5 audio playback is only supported by:
- iOS 4.2+
- Android 2.3+
Example
import mobl::ui::stylemixin
import mobl::ui::generic
import mobl::media
resource music.mp3
style playerBoxStyle {
border: 1px solid #444;
padding: 20px;
borderRadiusMixin(10px);
background: white;
width: 80%;
margin-left: auto;
margin-right: auto;
text-align: center;
}
screen root() {
header("Audio")
table {
row {
headerCol { "MP3 supported: " }
col { label(Audio.canPlayMp3() ? "Yes" : "No")}
}
row {
headerCol { "AAC supported: " }
col { label(Audio.canPlayAac() ? "Yes" : "No")}
}
row {
headerCol { "Ogg Vorbis supported: " }
col { label(Audio.canPlayVorbis() ? "Yes" : "No")}
}
row {
headerCol { "Wave supported: " }
col { label(Audio.canPlayWav() ? "Yes" : "No")}
}
}
when(Audio.canPlayMp3()) {
var audio = Audio.load("music.mp3")
block(playerBoxStyle) {
button("Play", onclick={
audio.play();
})
button("Pause", onclick={
audio.pause();
})
button("Reset", onclick={
audio.currentTime = 0;
})
label(Math.round(audio.currentTime))
block {
button("Louder", onclick={
audio.volume = Math.min(1, audio.volume + 0.1);
})
label(Math.round(audio.volume*10))
button("Softer", onclick={
audio.volume = Math.max(0, audio.volume - 0.1);
})
}
}
}
}
Static methods
load(url : String) : Audio
Loads and instantiates an Audio
object.
Example:
var audio = Audio.load("music.mp3");
audio.play();
canPlayMp3() : Bool
Returns whether the used browser is capable of playing MP3 media.
Example:
if(Audio.canPlayMp3()) {
alert("Play away!");
}
canPlayWav() : Bool
Returns whether the used browser is capable of playing wave media.
Example:
if(Audio.canPlayWav()) {
alert("Play away!");
}
canPlayVorbis() : Bool
Returns whether the used browser is capable of playing ogg vorbis media.
Example:
if(Audio.canPlayVorbis()) {
alert("Play away!");
}
canPlayAac() : Bool
Returns whether the used browser is capable of playing AAC media.
Example:
if(Audio.canPlayAac()) {
alert("Play away!");
}
Instance methods
play() : void
Starts sound playback.
Example:
audio.play();
pause() : void
Pauses sound playback.
Example:
audio.pause();
getDuration() : Num
The length of the sound clip in seconds.
Example:
var length = audio.getDuration();
destroy() : void
Unloads the media file and cleans up resources.
Example:
audio.destroy();
Instance properties
volume : Num
Value between 0 and 1 representing the playback volume. Note: not currently supported by mobile browsers.
Example:
audio.volume = 0.5;
currentTime : Num
Current playback time, in seconds.
Example:
alert(audio.currentTime);
mobl/media/audio.txt · Last modified: 2013/10/01 02:29 (external edit)