Video Player List

You must Login before you can answer or comment on any questions.

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();

— asked 9 months ago by Graham Jeffrey
7 Comments
  • Are you opening this window by setting it as the url property of a Window object??

    — commented 9 months ago by Anthony Decena

  • No

    — commented 9 months ago by Graham Jeffrey

  • Should i use like that?

    — commented 9 months ago by Graham Jeffrey

  • Show 4 more comments

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.

— answered 9 months ago by Alexander Bauer
answer permalink
3 Comments
  • this was at my first code, i have deleted that when u ask me, and use ~~~ url ~~~ property to open window.

    var win = Ti.UI.currentWindow;
    i have added the
    videoPlayer.addEventListener('complete', function(e) {
    outside of my function, is it ok now? did you see any problems ?

    and if you are ok this is my last question, i am trying to make it about 3 days but couldn't make it, this is my eventListener for adding name to database

    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);
    and this is the liste_ekle function
    var liste_ekle = function(listeadi){
        var db = Ti.Database.open('mydb');
        db.execute('INSERT INTO liste (baslik) VALUES (?)',listeadi);
        var lastID = db.lastInsertRowId;
        Ti.API.info(lastID);
        db.close();
    }
    it is working good, but when it automatically close the navgroup and return to the root, i can't see the added name, i have used many methods, but couldn't make it

    — commented 9 months ago by Graham Jeffrey

  • you need to refresh your view ising SELECT query after the insert, it wont do it for you.

    — commented 9 months ago by Alexander Bauer

  • thank you i will try , i wish i can figure that , thanks a lot

    — commented 9 months ago by Graham Jeffrey

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);

— answered 9 months ago by Graham Jeffrey
answer permalink
1 Comment
  • i have added my files, and if you can read my codes and give me your opinion i will be happy, this is my first database app , thank you

    — commented 9 months ago by Graham Jeffrey

Your Answer

Think you can help? Login to answer this question!