[AC-1886] Ti.Media not detected by compiler
| GitHub Issue | n/a |
|---|---|
| Type | Bug |
| Priority | n/a |
| Status | Closed |
| Resolution | Needs more info |
| Resolution Date | 2012-09-26T21:47:16.000+0000 |
| Affected Version/s | n/a |
| Fix Version/s | n/a |
| Components | Titanium SDK & CLI |
| Labels | n/a |
| Reporter | Shannon Hicks |
| Assignee | Shak Hossain |
| Created | 2012-09-05T07:21:29.000+0000 |
| Updated | 2016-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.
@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; });It's been 2 weeks now, closing due to age in no response.
Closing since the issue is not reproducible with 3.2+ of TISDK.