Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[TIMOB-14123] Android: Add support for creating video thumbnails #6393

Merged
merged 4 commits into from Dec 8, 2014

Conversation

ashcoding
Copy link
Contributor

No description provided.

@ashcoding
Copy link
Contributor Author

@ashcoding
Copy link
Contributor Author

Sample Code:

// this sets the background color of the master UIView (when there are no windows/tab groups on it)
Titanium.UI.setBackgroundColor('#000');

// create base UI tab and root window
//
function newWindow(){
var vidWin = Titanium.UI.createWindow({
    title : 'Tab 1',
    backgroundColor : '#fff'
});

var activeMovie = Titanium.Media.createVideoPlayer({
    top : 0,
    backgroundColor: 'red',
    height : 300,
    width : 300,
    //url : 'ten_sec_test.mp4'
    // url  :'http://www.quirksmode.org/html5/videos/big_buck_bunny.mp4'
});

activeMovie.url = 'http://www.quirksmode.org/html5/videos/big_buck_bunny.mp4';
//activeMovie.url = 'ten_sec_test.mp4';

var scrollView = Ti.UI.createScrollView({
    contentWidth : 'auto',
    contentHeight : 'auto',
    layout : 'horizontal',
    scrollType : 'horizontal'
});


activeMovie.requestThumbnailImagesAtTimes([0, 20, 59, 47, 22], Titanium.Media.VIDEO_TIME_OPTION_NEAREST_KEYFRAME, function(response) {
            Ti.API.info("Thumbnail callback called, success = " + response.success);
             Ti.API.info("Thumbnail callback called, time = " + response.time);
             Ti.API.info("Thumbnail callback called, code = " + response.code);
            if(response.success) {
                 var imgView = Titanium.UI.createImageView({
                    image : response.image
                });
                scrollView.add(imgView);

            }
        });
var cancelbtn = Ti.UI.createButton({bottom:0,width:200,height:50,title:'Cancel Request'});
cancelbtn.addEventListener('click',function(){
    Ti.API.info("Thumbnail Cancelled requested");
    activeMovie.cancelAllThumbnailImageRequests();
});


var closebtn = Ti.UI.createButton({bottom:60,width:200,height:50,title:'DONE'});
closebtn.addEventListener('click',function(){vidWin.close()});

vidWin.add(scrollView);
vidWin.add(closebtn);
vidWin.add(cancelbtn);
vidWin.open();
}

var win=Ti.UI.createWindow();
var openButton = Ti.UI.createButton({width:200,height:50,title:'open'});
openButton.addEventListener('click',newWindow);
win.add(openButton);
win.open();

@ashcoding
Copy link
Contributor Author

To test using a test mp4 file, put it in "assets/Resources" folder.

@@ -0,0 +1,57 @@
package ti.modules.titanium.media;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we really need this class? I think the only thing we do here is to track if the dataSource is set or not, since we are internally setting the datasource, can't we check there?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Noted. Removing this.

@ashcoding
Copy link
Contributor Author

New sample app.js code that includes showing the video player since video player code has changed. Change is due to sharing a helper class with thumbnail code.

// this sets the background color of the master UIView (when there are no windows/tab groups on it)
Titanium.UI.setBackgroundColor('#000');

// create base UI tab and root window
//
function newWindow(){
var vidWin = Titanium.UI.createWindow({
    title : 'Tab 1',
    backgroundColor : '#fff'
});

var activeMovie = Titanium.Media.createVideoPlayer({
    top : 0,
    backgroundColor: 'red',
    height : 300,
    width : 300,
    //url : 'ten_sec_test.mp4'
    // url  :'http://www.quirksmode.org/html5/videos/big_buck_bunny.mp4'
});

activeMovie.url = 'http://www.quirksmode.org/html5/videos/big_buck_bunny.mp4';
//activeMovie.url = 'ten_sec_test.mp4';

var scrollView = Ti.UI.createScrollView({
    contentWidth : 'auto',
    contentHeight : 'auto',
    layout : 'horizontal',
    scrollType : 'horizontal'
});
scrollView.add(activeMovie);

activeMovie.requestThumbnailImagesAtTimes([0, 20, 59, 47, 22], Titanium.Media.VIDEO_TIME_OPTION_NEAREST_KEYFRAME, function(response) {
            Ti.API.info("Thumbnail callback called, success = " + response.success);
             Ti.API.info("Thumbnail callback called, time = " + response.time);
             Ti.API.info("Thumbnail callback called, code = " + response.code);
            if(response.success) {
                 var imgView = Titanium.UI.createImageView({
                    image : response.image
                });
                scrollView.add(imgView);

            }
        });
var cancelbtn = Ti.UI.createButton({bottom:0,width:200,height:50,title:'Cancel Request'});
cancelbtn.addEventListener('click',function(){
    Ti.API.info("Thumbnail Cancelled requested");
    activeMovie.cancelAllThumbnailImageRequests();
});


var closebtn = Ti.UI.createButton({bottom:60,width:200,height:50,title:'DONE'});
closebtn.addEventListener('click',function(){vidWin.close()});

vidWin.add(scrollView);
vidWin.add(closebtn);
vidWin.add(cancelbtn);
vidWin.open();
}

var win=Ti.UI.createWindow();
var openButton = Ti.UI.createButton({width:200,height:50,title:'open'});
openButton.addEventListener('click',newWindow);
win.add(openButton);
win.open();

@salachi
Copy link
Contributor

salachi commented Dec 1, 2014

Latest changes looks good, I don't see any issues.

import android.net.Uri;
import android.os.Build;

public class TiDataSourceHelper {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just wondering why can't this be an inner class instead of a separate file by itself? It could also be a method?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

TiVideoView8 and TiThumbnailRetriever uses the same method. Hence I placed it there. Is there a better way to do this?

It originally was code that was in both files.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Have you try adding it as a static method in TiUIHelper?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok. I'll try it with that.

@ingo
Copy link
Contributor

ingo commented Dec 4, 2014

Attention: The contributor has signed the CLA

@ingo
Copy link
Contributor

ingo commented Dec 5, 2014

Attention: The contributor has signed the CLA

@hieupham007
Copy link
Contributor

Code reviewed and functionally tested. Request accepted

hieupham007 added a commit that referenced this pull request Dec 8, 2014
[TIMOB-14123] Android: Add support for creating video thumbnails
@hieupham007 hieupham007 merged commit f060cd8 into tidev:master Dec 8, 2014
@bitfabrikken
Copy link

The function requestThumbnailImagesAtTimes is still undefined in SDK 3.5.0.GA on Android - Any idea when it'll be included or where I can track the progress for GA? Edit: Nevermind, found it in Jira - it's coming in 3.6.0!

@ashcoding ashcoding deleted the timob-14123_with_docs branch May 21, 2015 07:24
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants