Skip to content

Instantly share code, notes, and snippets.

@arturoleon
Created September 14, 2012 04:58
Show Gist options
  • Save arturoleon/3719889 to your computer and use it in GitHub Desktop.
Save arturoleon/3719889 to your computer and use it in GitHub Desktop.
Stream video to ios/android
// this sets the background color of the master UIView (when there are no windows/tab groups on it)
Titanium.UI.setBackgroundColor('#000');
VideoStreamingTest = {};
Ti.include('streamingvideo.js');
// create tab group
var tabGroup = Titanium.UI.createTabGroup();
//
// create base UI tab and root window
//
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.createLabel({
color:'#999',
text:'I am Window 1',
font:{fontSize:20,fontFamily:'Helvetica Neue'},
textAlign:'center',
width:'auto'
});
*/
var videoButton = Ti.UI.createButton({
title: 'Play Video',
height: 40,
width:80
})
videoButton.addEventListener('click', function() {
VideoStreamingTest.video.playVideo()
});
//win1.add(label1);
win1.add(videoButton);
//
// create controls tab and root window
//
var win2 = Titanium.UI.createWindow({
title:'Tab 2',
backgroundColor:'#fff'
});
var tab2 = Titanium.UI.createTab({
icon:'KS_nav_ui.png',
title:'Tab 2',
window:win2
});
var label2 = Titanium.UI.createLabel({
color:'#999',
text:'I am Window 2',
font:{fontSize:20,fontFamily:'Helvetica Neue'},
textAlign:'center',
width:'auto'
});
win2.add(label2);
//
// add tabs
//
tabGroup.addTab(tab1);
tabGroup.addTab(tab2);
// open tab group
tabGroup.open();
(function() {
VideoStreamingTest.video = {};
//Make sure in your app.js that you include this file...."Ti.include('streamingvideo.js');"
//Call the below function from any basic window in your app.
//For example, create a basic window in app.js
//then call, "appname.video.playVideo();"
//on some event - like clicking a button (addEventListener on the button)
VideoStreamingTest.video.playVideo = function() {
//OPEN VIDEO......................................
var contentURL = '';
if((Ti.Platform.osname = 'iphone') || (Ti.Platform.osname = 'ipad' )){
//HTTP Live Streaming for iOS
contentURL = 'http://72.233.123.138:8180/m3ugen/broadcast/Congreso.mp4';
}
else {
//RTSTP for Android < 3.0
contentURL = 'rtsp://192.200.1.29/public/cf4be0f7998f4e8p';
}
//Create video player
var activeMovie = Titanium.Media.createVideoPlayer({
url: contentURL,
backgroundColor:'#111',
scalingMode:Titanium.Media.VIDEO_SCALING_ASPECT_FIT,
});
var videoWin = Titanium.UI.createWindow({
title: L('Video'),
backgroundColor:'#fff',
barColor: '#336699',
});
//If iOS 3.2 or above, add to Window - don't add for Android
if (parseFloat(Titanium.Platform.version) >= 3.2)
{
videoWin.add(activeMovie);
}
var windowClosed = false;
activeMovie.play();
//If iOS 3.2 or above, you can open from the tab- don't do that for Android
if (parseFloat(Titanium.Platform.version) >= 3.2)
{
tab1.open(videoWin);
}
else {
videoWin.open();
}
//Adding my own custom event listener
activeMovie.addEventListener('complete',function()
{
if (!windowClosed)
{
//Titanium.UI.createAlertDialog({title:'Movie', message:'Completed!'}).show();
}
activeMovie.remove;
activeMovie.release;
windowClosed = true;
videoWin.close();
});
};
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment