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.
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)
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!