user3608965
user3608965

Reputation: 39

How to get the video ended event in titanium appcelerator

I have load video url at run time using the setInterval() before assign video i am try to clear the setinterval
Also have used onComplete="donextcall" for assingn new video path to videoview but it fire twice so please help me

<VideoPlayer id="videoPlayersinglezone" ns="Ti.Media"  autoplay="true" height="100%" width="100%" onComplete="donextcall" url="" backgroundColor="black" />

var f = Ti.Filesystem.getFile(Ti.Filesystem.externalStorageDirectory +'SinglezoneData/', singleimgs[tempcall]);
clearInterval(x)
$.videoPlayersinglezone.url = f.nativePath;
$.videoPlayersinglezone.show();

I have using titanium 3.1.1 and alloy 1.2.2 anything missing please tell me.

Full code example

var common = require('common');
var singleimgs = [];
var fistentry = 0;

doFirstClickSingleZone();

function doFirstClickSingleZone() {

    var totalads = Titanium.App.Properties.getString('total_files_on_sdcard');
    $.videoPlayersinglezone.mediaControlStyle = Titanium.Media.VIDEO_CONTROL_HIDDEN;
    LoadData(totalads);

}

function LoadData(adscount) {

    var fistcall = 0;
    for (var i = 0; i < adscount; i++) {
        singleimgs[i] = Titanium.App.Properties.getString('dwnfname' + i);
    }        
}


var tempcall=0;
function donextcall() {
    /*
    fistentry++;
        if (fistentry % 2 == 0) {

        } else {

            tempcall++;
            RenderAd(tempcall);
        }
    */
    tempcall++;
    RenderAd(tempcall);
}

function RenderAd(imgid) {

    if (imgid == singleimgs.length) {
        tempcall = 0;
    } else {
        tempcall= imgid;
    }
    var t = Titanium.App.Properties.getString('timeInt');
    var x = setInterval(function() {
        if (tempcall < singleimgs.length) {
            var arry = [];
            arry = singleimgs[tempcall].split(".");
            var exte;
            exte = arry[arry.length - 1];

            if (exte == 'png' || exte == 'jpg' || exte == 'gif' || exte == 'jpeg' || exte == 'tif') {
                common.getnotification();
                $.videoPlayersinglezone.url = "";
                $.videoPlayersinglezone.hide();
                var f = Ti.Filesystem.getFile(Ti.Filesystem.externalStorageDirectory +'SinglezoneData/', singleimgs[tempcall]);

                $.myImg.image = f.nativePath;
                $.myImg.show();
                tempcall++;
            } else {
                //if(exte=='mp4' || exte=='avi' || exte=='3gp' || exte=='mov' || exte == 'flv'){
                common.getnotification();
                var f = Ti.Filesystem.getFile(Ti.Filesystem.externalStorageDirectory +'SinglezoneData/', singleimgs[tempcall]);

                //Titanium.App.Properties.setString('videopath', f.nativePath);
                //Titanium.App.Properties.setString('imgcount', tempcall++);
                $.myImg.image = '';
                $.myImg.hide();
                clearInterval(x);
                $.videoPlayersinglezone.url = f.nativePath;
                $.videoPlayersinglezone.show();

            }
        } else {
            common.getnotification();
            clearInterval(x);
            callAgain();
        }
    }, 10000);
}

//this callaAgain() I have use to call RenderAd(imgid) to display image or video randomly so u have any solution please help me my application aim to display image or video from sdcard randomly  
function callAgain() {
    RenderAd(singleimgs.length);
}

Upvotes: 0

Views: 144

Answers (0)

Related Questions