Reputation: 412
I have been developing an app that supports streaming video and audio, among other things. I've gotten everything to work perfectly on my iPhone 3S with iOS 4 as well as my Android device. Tonight, I deployed the app to my new iPhone 4S with iOS5 and now the VideoPlayer will not exit when I click on the "done" button on the top-left of the title bar! The video is playing full screen and I cannot get back to any of my application screens. Is this a known bug?
Here is my code for the view for review or to reproduce:
var contentURL = 'http://streaming.alburhan.tv/Video/GetURL/ME';
var win = Titanium.UI.currentWindow;
win.orientationModes = [Titanium.UI.PORTRAIT, Titanium.UI.LANDSCAPE_LEFT, Titanium.UI.LANDSCAPE_RIGHT];
var videoURL = "";
getURL:);
function getURL() {
var header, responseText;
//alert('Retrieving from ' + contentURL);
var xhr = Ti.Network.createHTTPClient();
xhr.timeout = 15000;
xhr.onload = function() {
try {
//alert('Connecting...');
Ti.API.info(this.responseText);
Ti.API.info(this.status);
if(this.status == 200) {
Ti.API.info('Response ' + this.responseText);
responseText = this.responseText;
} else {
Ti.API.info:'Status ' + this.status:;
Ti.API.info('Response ' + this.responseText:;
}
//alert:responseText);
if :responseText //alert:evaluated.URL);
videoURL = evaluated.URL;
var activeMovie = Titanium.Media.createVideoPlayer:{
contentURL: videoURL,
backgroundColor:'#111',
//movieControlMode:Titanium.Media.VIDEO_CONTROL_DEFAULT,
//scalingMode:Titanium.Media.VIDEO_SCALING_MODE_FILL
movieControlMode:Titanium.Media.VIDEO_CONTROL_FULLSCREEN,
scalingMode:Titanium.Media.VIDEO_SCALING_ASPECT_FIT,
sourceType:Titanium.Media.VIDEO_SOURCE_TYPE_STREAMING
}:;
if (parseFloat(Titanium.Platform.version) >= 3.2)
{
win.add(activeMovie);
}
var windowClosed = false;
activeMovie.addEventListener('complete',function()
{
if :!windowClosed)
{
//Titanium.UI.createAlertDialog:{title:'Movie', message:'Completed!'}:.show();
}
win.close:);
}:;
activeMovie.fullscreen = true;
activeMovie.play:);
win.addEventListener('close', function()
{
if (!windowClosed)
{
windowClosed = true;
//alert:"Window closed":;
activeMovie.stop();
}
});
}
else {
alert('Could not load video data from the server. Please try again later.');
}
}
catch(E){
alert('There was an error retrieving stream data from the server: ' + E);
}
};
xhr.onerror = function(e) {
Ti.API.debug(e.error);
alert('Could not connect to the server in order to retrieve stream data: ' + e.error);
};
xhr.open("GET", contentURL);
xhr.send();
}
Upvotes: 1
Views: 1238
Reputation: 412
Okay, I've fixed the issue. For anyone following this issue or who runs into it in the future, this is what I ended up doing/changing to get it to function properly on iOS 5:
movieControlMode:Titanium.Media.VIDEO_CONTROL_EMBEDDED
Also, I added the following event listeners:
activeMovie.addEventListener('complete', function() {
//alert('completed');
if (!windowClosed) {
activeMovie.fullscreen = true;
activeMovie.stop();
activeMovie.release();
windowClosed = true;
win.close();
}
});
activeMovie.addEventListener('fullscreen', function(e) { // When fullscreen status is changed.
if (!e.entering) { // User pressed 'done' or video finished.
activeMovie.fullscreen = true;
activeMovie.stop();
activeMovie.release();
windowClosed = true;
win.remove(activeMovie);
win.close();
}
});
Why I had to make these changes (especially the movieControlMode
) to get it working properly on iOS 5 is a mystery to me.
Upvotes: 2
Reputation: 1
Change this line:
activeMovie.fullscreen = true;
to this:
activeMovie.fullscreen = false;
I know, it makes no sense. Welcome to Titanium.
Upvotes: 0