Android video streaming

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

I've created an Android app to provide access to a large number of videos, mostly hosted at Blip. I don't need it to function on iPhone as there already is a native iPhone app performing the same function.

The videos are all m4v files (although for the blip ones I could get 3gp versions).

The code, pretty much ripped off from KitchenSink is, in essence:

var activeMovie = Ti.Media.createVideoPlayer({
            contentURL : url,
            mediaControlStyle : Ti.Media.VIDEO_CONTROL_DEFAULT,
            scalingMode : Ti.Media.VIDEO_SCALING_ASPECT_FIT
        });
 
        activeMovie.addEventListener('playbackState', function(e) {
            if (activeMovie.playbackState === Ti.Media.VIDEO_PLAYBACK_STATE_PLAYING)
                loadingActivity.hide();
        });
 
        if (parseFloat(Titanium.Platform.version) >= 3.2) {
            movieWindow.add(activeMovie);
        }
 
        movieWindow.open();
        activeMovie.play();
SDK: 2.1.2GA

Target: ideally 2.2 onwards, would settle for 2.3

The videos play fine on my Nexus running 4.0.4, and on the simulators running 3 or later, however under 2.2, 2.3 the video just never plays. It's also been tried on a tablet running 2.2 and that does the same.

I read somewhere that 3gp files would be more likely to play, but that doesn't appear to help.

Am I wasting my time trying to get this to work reliably under 2.2/2.3?

Thanks

3 Answers

http://developer.android.com/guide/appendix/media-formats.html

Two things at play here: codec and container.

— answered 9 months ago by Stephen Feather
answer permalink
1 Comment
  • Hi Stephen,

    Thanks for the link. The videos are H.264 m4v (mp4) files. So, if I'm reading this right it should work under 2.3?

    The line "For 3GPP and MPEG-4 containers, the moov atom must precede any mdat atoms, but must succeed the ftyp atom." doesn't mean much to me though. How do I check this?

    Cheers

    — commented 9 months ago by Nigel Harrison

Hi Nigel ;) Welcome to the world of Titanium!

I have a feeling that the earlier versions of Android didn't support H.264 (which is why I had to provide Flash/FLV versions for Mobods before - I don't support that now, since 2.3.x supports H.264)

— answered 9 months ago by Kosso .
answer permalink
4 Comments
  • Does 2.3? I can't get the videoplayer to play them, even ones that are recorded on the device itself, it wont stream them. I have to download them instead.

    — commented 9 months ago by Josh Lewis

  • 2.3.3 works for me.

    — commented 9 months ago by Kosso .

  • Hi Kosso,

    Thanks, again! The files are indeed H.264, but I can't seem to get this working.

    UPDATE: I've now been playing around with creating the movie player to run full screen and I'm closer - it starts playing, sound only, but then if I skip further on in the video I get pictures too. I need a 2.3 device to try on!!

    Cheers

    — commented 9 months ago by Nigel Harrison

  • Show 1 more comment

If anyone is interested, I'm going to answer my own question, this is what I ended up doing. It works from 2.3 onwards - tested on a number of devices. Emulators do not give a good representation at all!!

Unfortunately it seems the only way I could allow landscape viewing under 2.3 was to force it to landscape on play.

(function() {
 
    appName.ui.createPlayVideoWindow = function(url, title) {
 
        var loadingActivity;
        var movieWindow = Ti.UI.createWindow({
            id : 'winpv',
            title : title,
            backgroundColor : 'black',
            barColor : '#414444',
            navBarHidden : false,
            fullscreen : true
        });
 
        // force landscape on older versions of android
        if (parseFloat(Ti.Platform.version) < 3.0) {
            movieWindow.orientationModes = [Ti.UI.LANDSCAPE_LEFT, Ti.UI.LANDSCAPE_RIGHT];
        } else {
            movieWindow.orientationModes = [Ti.UI.LANDSCAPE_LEFT, Ti.UI.LANDSCAPE_RIGHT, Ti.UI.PORTRAIT, Ti.UI.UPSIDE_PORTRAIT];
        }
 
        var activeMovie = Ti.Media.createVideoPlayer({
            url : url,
            backgroundColor : '#111',
            mediaControlStyle : Ti.Media.VIDEO_CONTROL_DEFAULT,
            scalingMode : Ti.Media.VIDEO_SCALING_MODE_FIT
        });
 
        movieWindow.addEventListener('open', function() {
 
            loadingActivity = Ti.UI.createActivityIndicator({
                width : 50,
                height : 50,
                cancelable : true,
                message : 'Loading...'
            });
 
            loadingActivity.addEventListener('cancel', function() {
                if (!windowClosed) {
                    movieWindow.close();
                }
            })
            loadingActivity.show();
        });
 
        movieWindow.add(activeMovie);
        var windowClosed = false;
 
        activeMovie.addEventListener('complete', function() {
            if (!windowClosed) {
                movieWindow.close();
            }
        });
 
        activeMovie.addEventListener('playbackState', function(e) {
            if (e.playbackState === Ti.Media.VIDEO_PLAYBACK_STATE_PLAYING)
                loadingActivity.hide();
        })
 
        activeMovie.play();
 
        movieWindow.addEventListener('close', function() {
            if (!windowClosed) {
                windowClosed = true;
                activeMovie.stop();
            }
        });
 
        return movieWindow;
    }
})();

Your Answer

Think you can help? Login to answer this question!