Quantcast
Channel: Appcelerator Developer Center Q&A Tag Feed (done)
Viewing all articles
Browse latest Browse all 8

Fullscreen Video Player Example (Works!)

$
0
0

So I just spent several hours messing around with this code to finally get it working perfectly! There was very little help, I found more people stuck than helping. So I figured I would show my code to help everybody out.

If you are in need of a FULL SCREEN NATIVE VIDEO PLAYER, then this is the code for you. Simply put this code into a event listener for w/e you are needing to launch the video player.

var winVideo = Titanium.UI.createWindow({
    title:'Video Player',
    backButtonTitle: 'Videos',
    barColor: '#000',
    backgroundColor:'#000',
    orientationModes:[Ti.UI.LANDSCAPE_LEFT, Ti.UI.LANDSCAPE_RIGHT]
});
 
var videoPlayer = Titanium.Media.createVideoPlayer({
    url:'path_to_video',
    backgroundColor: '#000',
    fullscreen:true,
    scalingMode: Titanium.Media.VIDEO_SCALING_ASPECT_FIT,
    mediaControlMode: Titanium.Media.VIDEO_CONTROL_NONE     
});
 
winVideo.add(videoPlayer);
 
Titanium.UI.currentTab.open(winVideo,{animated:false});
 
videoPlayer.addEventListener('complete', function(e){
    if (e.reason == 0) {
        winVideo.close();
    };
});
 
videoPlayer.addEventListener('fullscreen', function(e){
    if (e.entering == 0) {
        winVideo.close();
    };
});
winVideo = The window that will take over your screen

videoPlayer = The actual video player that will be added to the window

complete = The event listener you need that will fire once video is completed

fullscreen = Another event listener you will need that will fire if user clicks the "Done" button

I hope this helps you guys a lot, I've seen people being stuck with the "Done" button, and the embedded video players. This should solve both problems!

P.S This code was only tested for iPhone, not sure on other platforms.


Viewing all articles
Browse latest Browse all 8

Latest Images

Trending Articles





Latest Images