2016-04-13 4 views
0

Videoaufzeichnung funktioniert auf IOS, Android kann keine Daten fangen.Video beabsichtigen nicht auf Android (Appcelerator) verwendet werden

Problem scheint die

var curActivity = Ti.Android.currentActivity; 
curActivity.startActivityForResult(intent, function(e) { .... 

es gab einige Ratschläge zu verwenden win.getActivity() statt, aber ich habe keine Variable zu sein, die ich verwenden können. $ .cameraWin diese funktioniert nicht. Irgendwelche Ratschläge?

index.xml

<Alloy> 
 
    <TabGroup>   
 
    <Tab id="websiteTab" title="Web"> 
 
      <Require backgroundColor="black" color="white" id="webTab" src="website" type="view"/> 
 
     </Tab> 
 
     <Tab id="cameraTab" title="Camera"> 
 
      <Require backgroundColor="black" color="white" id="cameraTab" src="camera" type="view"/> 
 
     </Tab> 
 
     <Tab backgroundColor="black" color="white" id="loginTab" title="Login"> 
 
      <Require backgroundColor="black" color="white" id="loginTab" src="login" type="view"/> 
 
     </Tab> 
 
     <Tab backgroundColor="black" color="white" id="registerTab" title="Map"> 
 
      <Require backgroundColor="black" color="white" id="registerTab" src="register" type="view"/> 
 
     </Tab> 
 
    </TabGroup> 
 
</Alloy>

camera.xml

<Alloy> 
 
    <Window id="cameraWin"> 
 
     <Label id="Label_1" text="Gib Deinem Video einen Namen"/> 
 
     <TextField id="TextField_1"/> 
 
     <Button id="Button_1" onClick="doClick" title="Aufnehmen und hochladen"/> 
 
     <ProgressBar id="ProgressBar_1"/> 
 
     <Picker id="Picker_1" selectionIndicator="true" useSpinner="true"> 
 
      <PickerColumn id="PickerColumn_1" title="Kategorie"> 
 
       <Row title="Fußball"/> 
 
       <Row title="Handball"/> 
 
       <Row title="Schifahren"/> 
 
       <Row title="Einkehren"/> 
 
      </PickerColumn> 
 
     </Picker> 
 
     <Label id="Label_2" text="Veranstaltung/Kategorie"/> 
 
    </Window> 
 
</Alloy>

camera.js

function doClick(e) { 
 
    Ti.API.info(Titanium.Platform.osname); 
 
    if (Titanium.Platform.osname == 'iphone') { 
 
    //record for iphone 
 
    $.ProgressBar_1.value = 0; 
 
    $.ProgressBar_1.message = "Hochladen" 
 
    Titanium.Media.showCamera({ 
 
     success: function(event) { 
 
     var video = event.media; 
 
     movieFile = Titanium.Filesystem.getFile(
 
      Titanium.Filesystem.applicationDataDirectory, 
 
      'mymovie.mov'); 
 

 
     movieFile.write(video); 
 
     videoFile = movieFile.nativePath; 
 
     var xhr = Titanium.Network.createHTTPClient(); 
 
     xhr.onload = function(e) { 
 
      Ti.UI.createAlertDialog({ 
 
      title: 'Success', 
 
      message: 'status code ' + this.status 
 
      }).show(); 
 
      Ti.API.info(this.responseText); 
 
     }; 
 
     xhr.open('POST', 'XXXXXXXXXX'); 
 
     xhr.send({ 
 
      Filedata: event.media, 
 
      /* event.media holds blob from gallery */ 
 
      title: $.TextField_1.value, 
 
      catid: 17 
 
     }); 
 
     // onsendstream called repeatedly, use the progress property to 
 
     // update the progress bar 
 
     xhr.onsendstream = function(e) { 
 
      $.ProgressBar_1.value = e.progress * 100; 
 
      $.ProgressBar_1.message = "Hochladen von Video"; 
 
      Ti.API.info('ONSENDSTREAM - PROGRESS: ' + e.progress * 100); 
 

 
     }; 
 

 

 
     }, 
 
     cancel: function() {}, 
 
     error: function(error) { 
 
     // create alert 
 
     var a = 
 
      Titanium.UI.createAlertDialog({ 
 
      title: 'Video' 
 
      }); 
 

 
     // set message 
 
     if (error.code == Titanium.Media.NO_VIDEO) { 
 
      a.setMessage('Device does not have video recording 
 
          capabilities '); 
 
     } else { 
 
      a.setMessage('Unexpected error: ' + error.code); 
 
     } 
 

 
     // show alert 
 
     a.show(); 
 
     }, 
 
     mediaTypes: Titanium.Media.MEDIA_TYPE_VIDEO, 
 
     videoMaximumDuration: 120000, 
 
     videoQuality: Titanium.Media.QUALITY_MEDIUM 
 
    }); 
 
    } else { 
 

 
    var intent = Titanium.Android.createIntent({ 
 
     action: 'android.media.action.VIDEO_CAPTURE' 
 
    }); 
 
    Ti.API.info('Intent created. ..'); 
 
    var curActivity = Ti.Android.currentActivity; 
 
    curActivity.startActivityForResult(intent, function(e) { 
 
     if (e.error) { 
 
     Ti.UI.createNotification({ 
 
      duration: Ti.UI.NOTIFICATION_DURATION_LONG, 
 
      message: 'Error: ' + e.error 
 
     }).show(); 
 
     } else { 
 
     Ti.API.info('Drinnen'); 
 
     Ti.Api.info(e.resultCode); 
 
     if (e.resultCode === Titanium.Android.RESULT_OK) { 
 
      Ti.API.info('Drinnen'); 
 
      videoFile = e.intent.data; 
 
      var source = Ti.Filesystem.getFile(videoFile); 
 
      var movieFile = 
 
      Titanium.Filesystem.getFile(Ti.Filesystem.applicationDataDirectory, 'mymovie.3gp'); 
 
      Ti.API.info('Sichert'); 
 
      source.copy(movieFile.nativePath); 
 
      Titanium.Media.saveToPhotoGallery(movieFile); 
 
      var xhr = Titanium.Network.createHTTPClient(); 
 
      xhr.onload = function(e) { 
 
      Ti.UI.createAlertDialog({ 
 
       title: 'Success', 
 
       message: 'status code ' + this.status 
 
      }).show(); 
 
      Ti.API.info(this.responseText); 
 
      }; 
 
      var fileContent = movieFile.read(); 
 
      Ti.API.info('Video rauf'); 
 
      xhr.open('POST', 'XXXXXXXXXXX' 
 
      Filedata: fileContent, 
 
      /* event.media holds blob from gallery */ 
 

 
      title: $.TextField_1.value, 
 
      catid: 17 
 
      }); 
 
      // onsendstream called repeatedly, use the progress property to 
 
      // update the progress bar 
 
      xhr.onsendstream = function(e) { 
 
      $.ProgressBar_1.value = e.progress * 100; 
 
      $.ProgressBar_1.message = "Hochladen von Video"; 
 
      Ti.API.info('ONSENDSTREAM - PROGRESS: ' + e.progress * 100); 
 

 
      }; 
 
     } else { 
 
      Ti.UI.createNotification({ 
 
      duration: Ti.UI.NOTIFICATION_DURATION_LONG, 
 
      message: 'Canceled/Error? Result code: ' + 
 
       e.resultCode 
 
      }).show(); 
 
     } 
 
     } 
 
    }); 
 

 
    } 
 
};

Antwort

1

Alternative Art und Weise:

arbeite ich zur Zeit Videoaufzeichnung auf immer in den normalen SDK für Android: https://github.com/appcelerator/titanium_mobile/pull/7929

Es arbeitet bereits (Samsung Galaxy S6 hat ein Problem einen Moment, den ich beheben muss: Sie müssen die Telefonen drehen, um die richtige Vorschaugröße zu haben), aber braucht noch mehr Tests. Damit können Sie die Kamera auf der Rück-/Frontkamera genauso aufzeichnen wie auf iOS.

Aber es muss noch einige Zeit in der GA-Version zu sein. Sie können immer ein eigenes SDK für sich selbst kompilieren, wenn Sie es sofort benötigen (ich kann einen Linux-Build bereitstellen).

0

Ich habe ein ähnliches Projekt, obwohl Mine Stills nehmen, nicht Video, sondern für alle Absichten und Zwecke sollen sie gleich verhalten.

In meinem Code habe ich:

var win = $.camera_view; 

Dies erlaubt mir später meine Tätigkeit zu beginnen:

win.activity.startActivityForResult(... 

Per Ihrem Beispiel Sie wahrscheinlich curActivity wie folgt gesetzt werden würde:

var curActivity = $.cameraWin.activity; 

[EDIT]

Wenn Sie immer noch kein Ergebnis Sie .putExtraUri verwenden können versuchen, den Speicherort angeben, um das Video zu speichern:

var tempfile = Ti.Filesystem.getFile(Ti.Filesystem.externalStorageDirectory, "tempvideo.mpg"); 
intent.putExtraUri("output",tempfile.nativePath); 

Sie würden diesen Satz vor startActivityForResult Aufruf.

Verwandte Themen