Titanium JIRA Archive
Appcelerator Community (AC)

[AC-1886] Ti.Media not detected by compiler

GitHub Issuen/a
TypeBug
Priorityn/a
StatusClosed
ResolutionNeeds more info
Resolution Date2012-09-26T21:47:16.000+0000
Affected Version/sn/a
Fix Version/sn/a
ComponentsTitanium SDK & CLI
Labelsn/a
ReporterShannon Hicks
AssigneeShak Hossain
Created2012-09-05T07:21:29.000+0000
Updated2016-03-08T07:40:48.000+0000

Description

The compiler seems to miss that Ti.Media is used when it's inside a function in an object:
var Rf = {media:{}};

// uncomment this to fix the compiler issue: 
// var test = Ti.Media.fireEvent('hi');

Rf.media.photo = {
 
key: 'photo',
  title: 'Photo',
  extension: 'jpg',
  type: 'image/jpeg',
  create: function(created) {
 
Ti.Media.showCamera({
  animated: false,
  saveToPhotoGallery: false,
  showControls: true,
  success: function() { 
 
var name = Rf.util.timestamp() + '.' + Rf.media.photo.extension;
Rf.write_to_new_file(name, media_item.media, function(file) {
created(file);
 
 
 
 });
      },
      error:function(error)
        {
        // create alert
        var a = Titanium.UI.createAlertDialog({title:'Camera'});
 
        // set message
        if (error.code == Titanium.Media.NO_CAMERA)
        {
            a.setMessage('Please run this test on device');
        }
        else
        {
            a.setMessage('Unexpected error: ' + error.code);
        }
 
        // show alert
        a.show();
    },
    cancel:function()
    {
 
    },
});
 
 
 }
};

Rf.media.photo.create(function(f){
	var test = f;
});
If you run this code, you get the "'undefined' is not an object (evaluating 'Ti.Media.showCamera')" error. If you un-comment the fireEvent line, everything works fine.

Comments

  1. Eduardo Gomez 2012-09-12

    @Shannon Hicks What is your iOS version? Just grabbed & installed your sample code directly on iPhone 4 with iOS 5.1 - got the camera working. I will leave this open for a while for further clarifications.

    Sample code

       var Rf = {media:{}};
        
       // uncomment this to fix the compiler issue: 
       // var test = Ti.Media.fireEvent('hi');
        
       Rf.media.photo = {
       
       	key : 'photo',
       	title : 'Photo',
       	extension : 'jpg',
       	type : 'image/jpeg',
       	create : function(created) {
       		
       		Ti.Media.showCamera({
       			animated : false,
       			saveToPhotoGallery : false,
       			showControls : true,
       			success : function() {
       
       				var name = Rf.util.timestamp() + '.' + Rf.media.photo.extension;
       				Rf.write_to_new_file(name, media_item.media, function(file) {
       					created(file);
       
       				});
       			},
       			error : function(error) {
       				// create alert
       				var a = Titanium.UI.createAlertDialog({
       					title : 'Camera'
       				});
       
       				// set message
       				if (error.code == Titanium.Media.NO_CAMERA) {
       					a.setMessage('Please run this test on device');
       				} else {
       					a.setMessage('Unexpected error: ' + error.code);
       				}
       
       				// show alert
       				a.show();
       			},
       			cancel : function() {
       
       			},
       		});
       
       	}
       };
       
       Rf.media.photo.create(function(f) {
       	var test = f;
       }); 
       
  2. Eduardo Gomez 2012-09-26

    It's been 2 weeks now, closing due to age in no response.
  3. Shak Hossain 2014-01-17

    Closing since the issue is not reproducible with 3.2+ of TISDK.

JSON Source