Titanium JIRA Archive
Titanium SDK/CLI (TIMOB)

[TIMOB-24400] Android: Download video and save it to the Device's Gallery

GitHub Issuen/a
TypeNew Feature
PriorityNone
StatusClosed
ResolutionFixed
Resolution Date2017-02-21T18:54:48.000+0000
Affected Version/sRelease 6.0.1
Fix Version/sRelease 6.1.0
ComponentsAndroid
Labelsvideo
ReporterVictor Vazquez Montero
AssigneeGary Mathews
Created2017-02-13T17:24:49.000+0000
Updated2017-02-22T23:12:02.000+0000

Description

Issue description:

We want to be able to download a video file from our servers to the device and save it on the gallery (upon user's approval). On iOS we accomplish this by this code:
var fileName = 'fileToDownload.mp4', 
       saveToGalleryFlag = true, 
       videoUrl = 'http://somedomain.com/fileToDownload.mp4';

var xhr = Titanium.Network.createHTTPClient({
		onload : function() {

			var f = Ti.Filesystem.getFile(Ti.Filesystem.applicationDataDirectory, fileName);

			// write to the file
			f.write(this.responseData);

			if (saveToGalleryFlag) {
				var blob = f.read();

/* According to Titanium docs, this does not save Videos on Android */
				Titanium.Media.saveToPhotoGallery(blob, {
					success : function(e) {
						console.log('-> SUCCESS');
					},
					error : function(e) {
						console.log('-> ERROR', e)
					}
				});
			}
		},
		timeout : 10000
	});

xhr.open('GET', videoUrl);
xhr.file = Titanium.Filesystem.getFile(Titanium.Filesystem.applicationDataDirectory, fileName);
xhr.send();

Expected Result:

Download videos into Android gallery/ file system upon users approval.

Comments

  1. Gary Mathews 2017-02-14

    master: https://github.com/appcelerator/titanium_mobile/pull/8837
  2. Lokesh Choudhary 2017-02-22

    Verified the new feature in SDK 6.1.0.v20170222102258. Works as expected. Closing.

JSON Source