Search code examples
androidvideotitaniumactivity-indicator

ProgressDialog before loading a video in Titanium


I am working at an Android app in Titanium. At a certain screen I must play a video from a link. It takes some time for charging so I must put a ProgressDialog until the video starts. I tried to use ActivityIndicator for this, like this :

var activeMovie = Titanium.Media.createVideoPlayer({
        backgroundColor:'#000',
        fullscreen:true
   });

   var dialog = Titanium.UI.createActivityIndicator();
    dialog.message = 'Loading...';

   win.add(dialog);
   dialog.show(); 

   activeMovie.setUrl(url);
   activeMovie.mediaControlStyle=Titanium.Media.VIDEO_CONTROL_FULLSCREEN;

   activeMovie.addEventListener("preload", function(e){
        dialog.show()  ;        
  });

   activeMovie.addEventListener('load', function(e){
        dialog.hide()  ;        
   });
   activeMovie.addEventListener('complete', function(e){
        activeMovie.stop();
        navController.close();
   });

This code make appear the ProgressDialog for 2 seconds and then disappear. After this time I get a black screen for a time (the video is charging) and after this time video starts. Can anyone help me where is my mistake?


Solution

  • One solution to your problem might be :

    var activeMovie = Titanium.Media.createVideoPlayer({
           url: url,
           backgroundColor:'#111',
           movieControlMode:Titanium.Media.VIDEO_CONTROL_DEFAULT // See TIMOB-2802, which may change this property name
    
        });
    
        win.add(activeMovie);
        var dlg = Titanium.UI.createActivityIndicator();
        win.addEventListener('open',function()
        {
               dlg.setMessage('Loading...');
               dlg.show();
        });
    
        activeMovie.addEventListener('load',function()
        {
               dlg.hide();
        });
    
        activeMovie.addEventListener('complete',function()
        {
               win.close();
        });
    
        activeMovie.play();
    
        win.addEventListener('close', function() 
        {
               windowClosed = true;
               activeMovie.stop();
        });