Closing window playing movie

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

I currently have a movie that plays after clicking a button in a view but when a user clicks done, the movie and window were not closing so I added an eventlistener to close the window but are now getting a script error that the variable "moviewin" could not be found.

var win = Titanium.UI.currentWindow;
win.backgroundColor = '#FFF';
 
var vertScrollView = Titanium.UI.createScrollView({
    contentWidth:'auto',
    contentHeight:'auto',
    top:0,
    bottom:0,
    showVerticalScrollIndicator:true,
    showHorizontalScrollIndicator:false
});
 
var view = Ti.UI.createView({
    backgroundColor:'#fff'
});
 
vertScrollView.add(view)
 
var intropic = Ti.UI.createImageView({
    image:'../images/pic',
    left:0,
    height:200,
    width:320,
    top:0,
})
view.add(intropic);
 
var movielabel = Ti.UI.createButton({
    title:'Play Movie',
    width:200,
    height:40,
    top:275
});
 
movielabel.addEventListener('click', function() 
{
    var moviewin = Titanium.UI.createWindow({
});
 
    var activeMovie = Titanium.Media.createVideoPlayer({
    url:'../images/movie.mp4',
        movieControlMode : Titanium.Media.VIDEO_CONTROL_DEFAULT,
        movieControlStyle : Titanium.Media.VIDEO_CONTROL_FULLSCREEN,
        scalingMode : Titanium.Media.VIDEO_SCALING_MODE_FILL,
        fullscreen:true,
        autoplay:false,
}); 
    moviewin.add(activeMovie);
    moviewin.open({fullscreen:true});
});
    moviewin.addEventListener('close', function() {
    activeMovie.stop();
    moviewin.close();
});
 
view.add(movielabel);
 
var view1 = Ti.UI.createView({
    backgroundColor:'#FFF'
});
 
 
var l = Ti.UI.createLabel({
    text:'View 1',
    width:300,
    height:'auto',
    top:12,
    font:{fontSize:24}
});
view1.add(l);
 
 
var view2 = Ti.UI.createView({
    backgroundColor:'#FFF'
});
 
var l2 = Ti.UI.createLabel({
    text:'View 2.',
    width:300,
    height:'auto',
    top:10,
    font:{fontSize:28}
});
view2.add(l2);
 
var view3 = Ti.UI.createView({
    backgroundColor:'green'
});
var l3 = Ti.UI.createLabel({
    text:'View 3',
    color:'#fff',
    width:'auto',
    height:'auto'
});
view3.add(l3);
 
var view4 = Ti.UI.createView({
    backgroundColor:'black'
});
var l4 = Ti.UI.createLabel({
    text:'View 4',
    color:'#fff',
    width:'auto',
    height:'auto'
});
view4.add(l4);
 
var scrollView = Titanium.UI.createScrollableView({
    views:[vertScrollView,view1,view2,view3,view4],
    showPagingControl:true,
    pagingControlHeight:25,
    maxZoomScale:2.0,
    currentPage:0
});
 
win.add(scrollView);
 
var i=1;
var activeView = view1;
 
scrollView.addEventListener('scroll', function(e)
{
    activeView = e.view;  // the object handle to the view that is about to become visible
    i = e.currentPage;
    Titanium.API.info("scroll called - current index " + i + ' active view ' + activeView);
});
scrollView.addEventListener('click', function(e)
{
    Ti.API.info('ScrollView received click event, source = ' + e.source);
});
scrollView.addEventListener('touchend', function(e)
{
    Ti.API.info('ScrollView received touchend event, source = ' + e.source);
});

— asked 10 months ago by J W
0 Comments

1 Answer

Accepted Answer

Hope this helps you:

var self = Ti.UI.createWindow({
        backgroundColor:'#000',
        title:'Trailer',
        orientationModes:[Ti.UI.LANDSCAPE_LEFT, Ti.UI.LANDSCAPE_RIGHT]
    });
 
    var activeMovie = Titanium.Media.createVideoPlayer({
        url: trailer,
        backgroundColor:'#000',
        mediaControlStyle: Ti.Media.VIDEO_CONTROL_DEFAULT,
        scalingMode: Ti.Media.VIDEO_SCALING_ASPECT_FIT,
        autoplay: true,
        fullscreen: true
    });    
 
    self.add(activeMovie);
 
    activeMovie.addEventListener('complete', function(e)
    {
        activeMovie.hide();
        activeMovie.release();
        activeMovie = null;
        self.close();
    });     
 
    activeMovie.addEventListener('fullscreen', function(e)
    {
        if (!e.entering && activeMovie != null)
            activeMovie.stop();
    });

Your Answer

Think you can help? Login to answer this question!