Titanium Community Questions & Answer Archive

We felt that 6+ years of knowledge should not die so this is the Titanium Community Questions & Answer Archive

Video Gallery

Hi , i would like to know if it is possible to get a video gallery for my application because it seems that the only gallery possible to implement is the photogallery

What can i do to display videos and then choose a video like the photogallery?

— asked April 22nd 2010 by Guillaume LAFOUTRY
  • android
  • gallery
  • iphone
  • mobile
  • video
0 Comments

6 Answers

  • If you want to just enable the choosing of videos from the built-in gallery picker, add mediaTypes: [Titanium.Media.MEDIA_TYPE_VIDEO] when you call Ti.Media.openPhotoGallery - then it will only show the videos in the gallery.

    — answered June 13th 2010 by Kosso
    permalink
    1 Comment
    • I can not get tHis to work. Can you post an complete example code to open photogallery with video.

      Would be great, thanks

      — commented July 30th 2010 by Jimmy Escherich
  • Hey Jimmy,

    did you manage to do it on Android?
    The solution Kosso suggested only works on iOS.

    My best regards!

    — answered April 10th 2012 by Douglas Alves
    permalink
    5 Comments
    • I found a solution for Android, but I am still struggling to get it working on Iphone.

          if(Ti.Platform.osname == 'android')
                  {
                      var intent = Titanium.Android.createIntent({ 
                          action: Ti.Android.ACTION_PICK,
                          type: "video/*"
                      }); //android.media.action.VIDEO_CAPTURE
      
                      intent.addCategory(Ti.Android.CATEGORY_DEFAULT);
      
                      window.activity.startActivityForResult(intent, function(e)
                      {
                          if (e.error) 
                          {
                              Ti.UI.createNotification({
                                  duration: Ti.UI.NOTIFICATION_DURATION_SHORT,
                                  message: 'Error: ' + e.error
                              }).show();
                          } 
                          else 
                          {
                               if (e.resultCode === Titanium.Android.RESULT_OK) 
                               {
                              videoFile = e.intent.data;
      
                                  var source = Ti.Filesystem.getFile(videoFile);
                                  movieFile = Titanium.Filesystem.getFile(Titanium.Filesystem.applicationDataDirectory, 'mymovie.3gp');
                                  source.copy(movieFile.nativePath);
      
                                     videoFile = movieFile.nativePath;
      
      
                                         r.onload = function() {
                                              var callback = JSON.parse(this.responseText);
      
                                              if (callback.status == 'ok'){}
                                      };
      
                                      xhr.onerror = function(e){};
      
                                      xhr.onsendstream = function(e){
                                      Ti.API.info('ControladorTelas - ON SEND STREAM - PROGRESS: ' + e.progress);
                              };
      
                                      if(movieFile.exists())
                                      {
                                              xhr.send({
                                                      video: source,
                                              });
                                                  movieFile.deleteFile();
                                         }
                                      else
                              {}
                                  } 
                                  else 
                                  {
                                      Ti.UI.createNotification({
                                              duration: Ti.UI.NOTIFICATION_DURATION_SHORT,
                                              message: 'Canceled!'
                                          }).show();
      
                                  }
                             }
                     });
                  }
      

      — commented July 11th 2012 by Douglas Alves
    • Dude thank you so much =).

      — commented November 2nd 2012 by Mauricio Stand
    • Maurício,

      I found the solution for the Iphone as well! :)

      Ti.Media.openPhotoGallery({
          allowEditing: true,
          mediaTypes: [Ti.Media.MEDIA_TYPE_VIDEO],
          success:function(event) {                    
              xhr_video = Ti.Network.createHTTPClient({enableKeepAlive:false});
              xhr_video.onload = function(e){
                  Ti.API.info("OK: " + this.responseText);
      
                  Ti.UI.createAlertDialog({
                      title: 'Success',
                      message: 'Video uploaded',
                      OK: 'OK'
                  }).show();
              };
      
              xhr_video.timeout = config.TimeOut();
      
              xhr_video.onerror = function(e){ 
                   Ti.API.info('ERROR => ' + e.error);
              };
      
              xhr_video.onsendstream = function(e){
                  Ti.API.info('ONSENDSTREAM - PROGRESS: ' + e.progress);
              };
      
              xhr_video.open('POST', 'http://myServer/video_upload');
              xhr_video.send({
                  video: event.media  //video,
              });
          }
      });
      

      — commented November 12th 2012 by Douglas Alves
    • Hello Douglas,

      I have tested this code with SDK 3.0 and iOS5.1 and the video (event.media) is sent compressed to the server. Is there any way to send it withot compression?
      It seems like photogallery is returning the video compressed, Does it right?

      Thanks.

      — commented December 29th 2012 by Koldo Calvo
    • I found the answer myself. The problem I had was that event.media returns a mimetype of mpeg but video really works if I add the .mov extension to the filename I upload to the server.

      — commented January 8th 2013 by Koldo Calvo
  • It would like to upload videos after choosing or capturing. It is possible 2 months later? Please can i have a clear answer to know if i have to give up Titanium or not because it's very urgent.

    Thanks

    — answered April 29th 2010 by Guillaume LAFOUTRY
    permalink
    0 Comments
  • It would like to upload videos after choosing or capturing. It is possible 2 months later? Please can i have a clear answer to know if i have to give up Titanium or not because it's very urgent.

    Thanks

    — answered June 13th 2010 by Guillaume LAFOUTRY
    permalink
    0 Comments
  • if (Ti.Platform.osname == 'android') {
                    var intent = Titanium.Android.createIntent({
                        action : Ti.Android.ACTION_PICK,
                        type : "video/*"
                    });
                    //android.media.action.VIDEO_CAPTURE
                    intent.addCategory(Ti.Android.CATEGORY_DEFAULT);
                    self.activity.startActivityForResult(intent, function(e) {
                        if (e.error) {
                            Ti.UI.createNotification({
                                duration : Ti.UI.NOTIFICATION_DURATION_SHORT,
                                message : 'Error: ' + e.error
                            }).show();
                        } else {
                            if (e.resultCode === Titanium.Android.RESULT_OK) {
                                videoFile = e.intent.data;
                                var source = Ti.Filesystem.getFile(videoFile);
                                movieFile = Titanium.Filesystem.getFile(Titanium.Filesystem.applicationDataDirectory, 'mymovie.3gp');
                                source.copy(movieFile.nativePath);
                                videoFile = movieFile.nativePath;
                                scene_picker(source);
                            } else {
                                Ti.UI.createNotification({
                                    duration : Ti.UI.NOTIFICATION_DURATION_SHORT,
                                    message : 'Canceled!'
                                }).show();
                            }
                        }
                    });
                }
    
    — answered January 11th 2013 by Sedat Bilen
    permalink
    1 Comment
    • there is a function of mine in it which you can simply remove which is:

      scene_picker(source);
      

      — commented January 11th 2013 by Sedat Bilen
  • I am also still not able to view the video in the photogallary. Is there any solution. The code i have used is as below.

    Titanium.Media.openPhotoGallery({
    success : function(event) {
    Ti.API.debug('Our type was: ' + event.mediaType);
    if (event.mediaType == Ti.Media.MEDIA_TYPE_PHOTO || Ti.Media.MEDIA_TYPE_VIDEO) {
    UploadPhotoToServer(event.media);
    }
    },
    cancel : function() {
    },
    error : function(err) {
    Ti.API.error(err);
    },
    mediaTypes : [Ti.Media.MEDIA_TYPE_PHOTO, Ti.Media.MEDIA_TYPE_VIDEO]
    });

    — answered April 19th 2013 by kabindra simkhada
    permalink
    0 Comments
The ownership of individual contributions to this community generated content is retained by the authors of their contributions.
All trademarks remain the property of the respective owner.