Titanium Community Questions & Answer Archive

We felt that 6+ years of knowledge should not die so this is the Titanium Community Questions & Answer Archive

videoplayer - loading a media file

I am trying to switch and play media files that are packaged with the application.

Creating new instances of the player, one for each media file, creates issues (black blinking of the left third of the view area) and flicker between new instance and previous clip.

Tried using setUrl() and contentUrl and url. None of them will load a media file.

Am now trying setMedia() but am stuck with loading a file object (there is zero doc on this) .

Any help is greatly appreciated.

— asked May 10th 2010 by Iko Knyphausen
  • file
  • ipad
  • system
0 Comments

4 Answers

  • I've been able to create new video player instances without experiencing the issues you've reported. Can you create a small test case that reproduces the issue you are seeing?

    Thanks…

    — answered May 10th 2010 by Kevin Whinnery
    permalink
    0 Comments
  • Thanks for taking this on. I'll give you 2 examples. Both work off a table when a new movie is selected in the tableView. The table data has one field called "movie" and it has a string with a filename. These files are part of the resources directory.

    1. The simplest way is to create a new instance and to add it to the container view. This method has 2 issues: (a) there is a brief flicker when selecting a new movie. The screen goes dark, then shows the previous movie (1 still frame), then shows the new movie still frame. (b) If you go back an forth a couple of times, a black bar will appear at either right or left side, covering approx. 1/3 of the view…

    Here is the code:

    var data = [
        {title:'Home production 1', movie: 'movie1.mp4' },
        {title:'Home production 2', movie: 'movie2.mp4' },
        {title:'Home production 3', movie: 'movie3.mp4' }
    ];
    
    var tableView = Titanium.UI.createTableView({
        data: data,
        backgroundColor:'#fff',
        separatorColor: '#000',
        separatorStyle: 0,
        width: 240,
        cornerRadius: 5,
        borderWidth: 1,
        borderColor: '#000',
        opacity: 1,
        left: 10,
        top: 10,
        bottom: 10
    });
    
    var videoView = Titanium.UI.createView({  
                backgroundColor:'#000',
                left : 280,
                right: 30,
                height: 331,
                opacity : 1,
                borderWidth: 0
                });
    
    tableView.addEventListener('click', function(e)
    {
    
        if (e.rowData.movie)
        {
    
            var activeMovie = Titanium.Media.createVideoPlayer({
                url: e.rowData.movie,
                backgroundColor: '#000',
                scalingMode:Titanium.Media.VIDEO_SCALING_ASPECT_FIT
                });
    
            videoView.add(activeMovie);
        }
    });
    
    1. To get rid of the flicker between selected videos, I also tried putting the activeMovie variable outside of the eventhandler, so that I could unload the window and/or release the video resources before loading the next clip. It takes care of the flicker between vids but sometimes the video view area goes blank (almost like a timing issue=as if the release happens after the new vid is loaded). Problem (b) from the first example is still there as well.
    
    var activeMovie = null;
    tableView.addEventListener('click', function(e)
    {
    
        if (e.rowData.movie)
        {
    
            if (activeMovie)
            {
                videoView.remove(activeMovie); // i tried all 3 variations
                activeMovie.release();
            }
    
    
            activeMovie = Titanium.Media.createVideoPlayer({
                url: e.rowData.movie,
                backgroundColor: '#000',
                scalingMode:Titanium.Media.VIDEO_SCALING_ASPECT_FIT
                });
    
            videoView.add(activeMovie);
        }
    });
    

    thanks much for your help.

    — answered May 10th 2010 by Iko Knyphausen
    permalink
    0 Comments
  • I should add: issue (b) only happens on the iPad itself, not in the simulator!

    — answered May 10th 2010 by Iko Knyphausen
    permalink
    0 Comments
  • We are getting closer… The above code will not always produce the symptoms I described earlier. In my application I have another container view "around", and that reproduces the issue reliably. The window hierarchy is as follows: appWin -> details -> videoView -> activeMovie (this is the player)

    the full code:

    var appWin = Titanium.UI.createWindow();
    appWin.open();
    
    var details = Titanium.UI.createView({ left:290, top: 75, right: 30, bottom: 30, backgroundColor: '#fff', borderColor: '#666', borderRadius: 10, borderWidth:5,  opacity: 1 });
    
    var data = [
        {title:'Home production 1', movie: 'movie1.mp4' },
        {title:'Home production 2', movie: 'movie2.mp4' },
        {title:'Home production 3', movie: 'movie3.mp4' }
    ];
    
    var tableView = Titanium.UI.createTableView({
        data: data,
        backgroundColor:'#fff',
        separatorColor: '#000',
        separatorStyle: 0,
        width: 240,
        cornerRadius: 5,
        borderWidth: 1,
        borderColor: '#000',
        opacity: 1,
        left: 10,
        top: 10,
        bottom: 10
    });
    
    var videoView = Titanium.UI.createView({  
                backgroundColor:'#000',
                left : 38,
                right: 40,
                height: 331,
                opacity : 1,
                borderWidth: 0
                });
    
    
    
    tableView.addEventListener('click', function(e)
    {
    
        if (e.rowData.movie)
        {
    
            var activeMovie = Titanium.Media.createVideoPlayer({
                url: e.rowData.movie,
                backgroundColor: '#000',
                scalingMode:Titanium.Media.VIDEO_SCALING_ASPECT_FIT
                });
    
            videoView.add(activeMovie);
        }
    });
    
    appWin.add(tableView);
    details.add(videoView);
    appWin.add(details);
    
    — answered May 11th 2010 by Iko Knyphausen
    permalink
    0 Comments
The ownership of individual contributions to this community generated content is retained by the authors of their contributions.
All trademarks remain the property of the respective owner.