Titanium JIRA Archive
Titanium SDK/CLI (TIMOB)

[TIMOB-7623] iOS: VideoPlayer.requestThumbnailImagesAtTimes only calls callback once.

GitHub Issuen/a
TypeBug
PriorityHigh
StatusClosed
ResolutionFixed
Resolution Date2012-07-06T02:44:06.000+0000
Affected Version/sRelease 1.8.1
Fix Version/sSprint 2012-05, Release 2.0.0
ComponentsiOS
Labelsmodule_media, parity, qe-testadded, release-note
ReporterArthur Evans
AssigneeVishal Duggal
Created2012-02-10T17:16:39.000+0000
Updated2012-07-09T11:54:11.000+0000

Description

The method is invoked like this: myMovie.requestThumbnailImagesAtTimes(times, option, callback) This method is supposed to provide a series of thumbnails. For each time offset in the "times" array, it's supposed to generate a thumbnail and invoke the callback. Looking at the code, it looks like the callback is being discarded after the first use. Test case: the following code should retrieve multiple thumbnails, and display them in the scrollview at the bottom. But in practice, only the first thumbnail is retrieved.
// 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
//
var vidWin = Titanium.UI.createWindow({
	title : 'Tab 1',
	backgroundColor : '#fff'
});

var activeMovie = Titanium.Media.createVideoPlayer({
	top : 0,
	backgroundColor: 'red',
	height : 300,
	width : 300,
	borderRadius : 20,
	borderWidth : 2,
	borderColor : 'blue',
	mediaControlStyle : Titanium.Media.VIDEO_CONTROL_EMBEDDED,
	scalingMode : Titanium.Media.VIDEO_SCALING_ASPECT_FILL
});




if(Ti.Platform.name == 'iPhone OS') {
	activeMovie.addEventListener('durationAvailable', function(evt) {
		Ti.API.info("Requesting thumbnails now.");
		var duration = activeMovie.duration/1000.0;
		activeMovie.requestThumbnailImagesAtTimes([0, duration / 2, duration], Titanium.Media.VIDEO_TIME_OPTION_NEAREST_KEYFRAME, function(response) {
			Ti.API.info("Thumbnail callback called, success = " + response.success);
			if(response.success) {
				var ratio = scrollView.size.height / response.image.height;
				var imgView = Titanium.UI.createImageView({
					width : (response.image.width * ratio),
					height : (response.image.height * ratio),
					image : response.image
				});
				scrollView.add(imgView);
			}
		});
	});
}
//activeMovie.url = contentURL;
activeMovie.url = 'movie.mp4';
vidWin.add(activeMovie);

var scrollView = Ti.UI.createScrollView({
	width : '100%',
	height : '30%',
	contentWidth : 'auto',
	contentHeight : 'auto',
	layout : 'horizontal',
	scrollType : 'horizontal',
	bottom : 0,
});

//view.add(imgView);
vidWin.add(scrollView);
vidWin.open();

Comments

  1. Vishal Duggal 2012-02-17

    Updating example to use correct duration
  2. Philippe Elsass 2012-02-25

    Additional bug: - the app crashes if the callback is omitted although the doc indicates the param is optional, - the VideoPlayer doesn't dispatch the 'thumbnail' event. Notes: - a breakpoint in the obj-c code at the beginning of 'handleThumbnailImageRequestFinishNotification' shows that all the frames are generated, but the callback is released upon first reception.
  3. Philippe Elsass 2012-02-26

    Here's a patch, but changing the API slightly: all the thumbnails are returned as one event. https://gist.github.com/1917875
  4. Vishal Duggal 2012-02-29

    Pull pending #1537.
  5. Blain Hamon 2012-02-29

    To test circular retain leakage, use the following:
       // 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,
       	borderRadius : 20,
       	borderWidth : 2,
       	borderColor : 'blue',
       	mediaControlStyle : Titanium.Media.VIDEO_CONTROL_EMBEDDED,
       	scalingMode : Titanium.Media.VIDEO_SCALING_ASPECT_FILL
       });
       
       if(Ti.Platform.name == 'iPhone OS') {
       	activeMovie.addEventListener('durationAvailable', function(evt) {
       		Ti.API.info("Requesting thumbnails now.");
       		var duration = activeMovie.duration/1000.0;
       
       		activeMovie.requestThumbnailImagesAtTimes([0, duration / 2, duration], Titanium.Media.VIDEO_TIME_OPTION_NEAREST_KEYFRAME, function(response) {
       			Ti.API.info("Thumbnail callback called, success = " + response.success);
       			if(response.success) {
       				var ratio = scrollView.size.height / response.image.height;
       				var imgView = Titanium.UI.createImageView({
       					width : (response.image.width * ratio),
       					height : (response.image.height * ratio),
       					image : response.image
       				});
       				scrollView.add(imgView);
       			}
       		});
       
       	});
       }
       //activeMovie.url = contentURL;
       activeMovie.url = 'movie.mp4';
       vidWin.add(activeMovie);
       
       var scrollView = Ti.UI.createScrollView({
       	width : '100%',
       	height : '30%',
       	contentWidth : 'auto',
       	contentHeight : 'auto',
       	layout : 'horizontal',
       	scrollType : 'horizontal',
       	bottom : 0,
       });
       
       var closebtn = Ti.UI.createButton({bottom:50,width:200,height:50,title:'DONE'});
       closebtn.addEventListener('click',function(){vidWin.close()});
       //view.add(imgView);
       vidWin.add(scrollView);
       vidWin.add(closebtn);
       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();
       
  6. Blain Hamon 2012-03-02

    Pull request #1537 approved.
  7. Wilson Luu 2012-03-15

    Closing bug. Verified fix on: SDK build: 2.0.0.v20120315170247 Titanium Studio, build: 2.0.0.201203142055 xcode: 4.2 Device: iphone 4s (5.0.1)
  8. Anshu Mittal 2012-07-06

    Reopening to update labels

JSON Source