Hello, i am using the videoPlayer below, it pulls data from the database and it is working good, but i am not sure is this code correct? and i have a strange problem, when i open this from a navgroup, after playing and stop it and turn back to main window sometimes it crashes? what can i do for this?
var win = Ti.UI.currentWindow; win.orientationModes = [Ti.UI.LANDSCAPE_LEFT, Ti.UI.LANDSCAPE_RIGHT]; var videosToPlay = []; if (videosToPlay.length ==0 ){ db = Ti.Database.open('mydb'); dbrows = db.execute('SELECT * FROM videos WHERE cat = 1'); while (dbrows.isValidRow()){ videosToPlay.push({ video:"http://www.xxx.com"+ dbrows.fieldByName('video'), name:dbrows.fieldByName('baslik') }); dbrows.next(); } dbrows.close(); } //Ti.API.info(videosToPlay); var index; var index = 0; // This variable keeps tabs on which video is currently playing. var videoPlayer; videoPlayer = Ti.Media.createVideoPlayer({ fullscreen:true, autoplay:true }); function loopvideoPlayer() { videoPlayer.url = videosToPlay[index].video; videoPlayer.name = videosToPlay[index].name; Ti.API.info("Total Video:"+videosToPlay.length); videoPlayer.addEventListener('complete', function(e) { index ++; if (index < videosToPlay.length){ Ti.API.info("Playing:"+index); loopvideoPlayer(); } else { alert("Playing list finished, turn to beginning"); index = 0; loopvideoPlayer(); } }); videoPlayer.play(); } loopvideoPlayer(); win.add(videoPlayer); win.open();
2 Answers
Accepted Answer
var win = Ti.UI.currentWindow;how does this work if you are not using URL?
Also:
videoPlayer.addEventListener('complete', function(e) { ...you should Not add the eventListener Inside the function, this will end in n Videos = n listeners which may Lead to OutOfRange exception.
This is my main file named as "listeler.js"
Ti.include("functions.js"); var baseWin = Ti.UI.currentWindow; baseWin.navBarHidden = true; baseWin.backgroundColor = '#000'; var win = Ti.UI.createWindow({ title:'Listelerim', barColor:'#000', backgroundColor:'#131313' }); liste_al(); var ekle = Ti.UI.createButton({ title:'Liste Ekle' }); win.setRightNavButton(ekle); ekle.addEventListener('click',function(e){ // SETTING UP MY WINDOW var ekle_pencere = Ti.UI.createWindow({ title:'Yeni Liste Ekle', barColor:'#000' }); // CREATING MY TEXTFIELD var isim = Ti.UI.createTextField({ color:'#000', top:10, left:10, right:10, width:300, height:30, hintText:'Liste Ad?', keyboardType:Titanium.UI.KEYBOARD_DEFAULT, returnKeyType:Titanium.UI.RETURNKEY_DEFAULT, borderStyle:Titanium.UI.INPUT_BORDERSTYLE_ROUNDED }); // SENDING VARIABLES var gonder = Ti.UI.createButton({ title:"Ekle", width:50, height:30, backgroundColor:'#1e1e1e', top:150, right:50 }); // WINDOW ADD EVENT LISTENER ekle_pencere.addEventListener("click",function(e){ isim.blur(); }); // BUTTON ADD EVENT LISTENER gonder.addEventListener("click",function(e){ liste_ekle(isim.value); alert("Listeniz Eklendi"); navGroup.close(ekle_pencere); navGroup.open(win); }); // ADDING VARIABLES ekle_pencere.add(isim); ekle_pencere.add(gonder); // NAVGROUP OPEN navGroup.open(ekle_pencere); }); win.add(categoryTableView); categoryTableView.addEventListener("click",function(e){ var idim; idim = e.row.data.id; var klip_pencere = Ti.UI.createWindow({ title:e.row.data.baslik, barColor:'#000', backgroundColor:'#131313' }); var izle = Ti.UI.createButton({ title:'?zle' }); klip_pencere.setRightNavButton(izle); var izlenecek_kategori = e.row.data.id; izle.addEventListener("click",function(e){ var izle_pencere = Ti.UI.createWindow({ backgroundColor:'#FFF', barColor:'#000', title:izlenecek_kategori, url:'video_listesi_oynat.js', orientationModes: [Ti.UI.LANDSCAPE_LEFT, Ti.UI.LANDSCAPE_RIGHT] }); izle_pencere.katID = izlenecek_kategori; navGroup.open(izle_pencere); }); klip_liste_al(e.row.data.id); klip_pencere.add(klipTableView); klipTableView.addEventListener("click",function(e){ var klip_idim; klip_idim = e.row.data.id; Ti.API.info(klip_idim); var adres_izin = Titanium.UI.createAlertDialog({ message:'Klibi listenizden silmek istedi?inize emin misiniz?', buttonNames: ['Evet','Hay?r'] }); adres_izin.show(); adres_izin.addEventListener('click',function(e) { if (e.index == 0) { Ti.API.info("Silinen Klip ID:"+klip_idim); klip_sil(klip_idim); navGroup.close(klip_pencere); navGroup.open(win); } }); }); navGroup.open(klip_pencere,{animate:true}); }); var navGroup = Ti.UI.iPhone.createNavigationGroup( { window : win }); win.navGroup = navGroup; baseWin.add(navGroup); baseWin.open()this is my video_listesi_oynat.js file
var izle_pencere = Ti.UI.currentWindow; izle_pencere.backgroundColor = '#000'; izle_pencere.orientationModes = [Ti.UI.LANDSCAPE_LEFT, Ti.UI.LANDSCAPE_RIGHT]; var katID, izle_pencere; katID = izle_pencere.katID; Ti.API.info("Gelen ID:"+katID) var videosToPlay = []; if (videosToPlay.length ==0 ){ db = Ti.Database.open('mydb'); dbrows = db.execute('SELECT * FROM klipler WHERE kategori = ?',katID); while (dbrows.isValidRow()){ videosToPlay.push({ video:"http://www.xxx.com"+ dbrows.fieldByName('videoadresi_mp4'), name:dbrows.fieldByName('baslik') }); dbrows.next(); } dbrows.close(); } //Ti.API.info(videosToPlay); var index; var index = 0; // This variable keeps tabs on which video is currently playing. var videoPlayer; videoPlayer = Ti.Media.createVideoPlayer({ fullscreen:false, autoplay:false, mediaControlStyle : Titanium.Media.VIDEO_CONTROL_DEFAULT, scalingMode : Titanium.Media.VIDEO_SCALING_ASPECT_FIT, top:0 }); function loopvideoPlayer() { videoPlayer.url = videosToPlay[index].video; videoPlayer.name = videosToPlay[index].name; //Ti.API.info(videoPlayer.url); //Ti.API.info(videoPlayer.name); Ti.API.info("Toplam Klip Say?s?:"+videosToPlay.length); videoPlayer.addEventListener('complete', function(e) { index ++; if (index < videosToPlay.length){ Ti.API.info("Çalan Klip S?ras?:"+index); loopvideoPlayer(); } else { index = 0; loopvideoPlayer(); } }); videoPlayer.play(); } loopvideoPlayer(); izle_pencere.add(videoPlayer);
Your Answer
Think you can help? Login to answer this question!