Created
January 29, 2012 15:17
-
-
Save yagitoshiro/1699244 to your computer and use it in GitHub Desktop.
Titanium m3u audio streaming test
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Titanium.UI.setBackgroundColor('#000'); | |
var tabGroup = Titanium.UI.createTabGroup(); | |
var win1 = Titanium.UI.createWindow({ | |
title:'Tab 1', | |
backgroundColor:'#fff' | |
}); | |
var tab1 = Titanium.UI.createTab({ | |
icon:'KS_nav_views.png', | |
title:'Tab 1', | |
window:win1 | |
}); | |
var label1 = Titanium.UI.createButton({ | |
top:100, | |
title:'open player', | |
textAlign:'center', | |
width:120, | |
height:30, | |
borderWidth:'1px', | |
borderRadius:'10px' | |
}); | |
var songs = []; | |
var counter = 0; | |
songs.push('http://example.com/test1.m4a'); | |
songs.push('http://example.com/test2.m4a'); | |
songs.push('http://example.com/test3.m4a'); | |
songs.push('http://example.com/test4.m4a'); | |
var max = songs.length; | |
Titanium.Media.audioSessionMode = Titanium.Media.AUDIO_SESSION_MODE_PLAYBACK; | |
function create_player(url, fn){ | |
var player = Ti.Media.createVideoPlayer({url:url, autoplay:true}); | |
player.addEventListener('preload', function(e){ | |
fn(); | |
}); | |
player.addEventListener('complete', function(e){ | |
Ti.API.info(e); | |
if(e.reason == 0){ | |
counter++; | |
if(counter < max){ | |
callback = function(){ | |
win1.remove(player); | |
}; | |
create_player(songs[counter], callback); | |
}else{ | |
counter = 0; | |
} | |
} | |
}); | |
win1.add(player); | |
player.play(); | |
} | |
label1.addEventListener('click', function(){ | |
create_player(songs[counter], function(){}); | |
}); | |
win1.add(label1); | |
tabGroup.addTab(tab1); | |
tabGroup.open(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment