Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Initial Call Error: SyntaxError: Unexpected token u in JSON at position 0 #2

Open
Stakdek opened this issue Nov 25, 2020 · 3 comments

Comments

@Stakdek
Copy link

Stakdek commented Nov 25, 2020

Error-Message:

file:///android_asset/www/js/cordova-media-upload.js: Line 39 : Uncaught (in promise) SyntaxError: Unexpected token u in JSON at position 0
chromium: [INFO:CONSOLE(39)] "Uncaught (in promise) SyntaxError: Unexpected token u in JSON at position 0", source: file:///android_asset/www/js/cordova-media-upload.js (39)

Specs:

Device: Android Cordova App on Datalogic Memor 10 with Android 8.1.0
Cordova: 8.1.2 ([email protected])
Build on: Ubuntu 20.04

Code:

const cmu = new CordovaMediaUpload({
  "imageWidth": 640,
  "imageHeight": 480,
  "imageQuality": 50,
  "videoWidth": 640,
  "videoHeight": 480,
  "videoBitRate": 1000000
});

function getMedia(callback){
  cmu.getVideo()
    .then(data => {
      showUserAlert(data);
      callback();
    })
    .catch(error => {
      if(error) {
        navigator.notification.alert(_('album.failure'));
        showUserAlert(error); // shows message box on page
        throw error;
      }
    })
}

Already tried with

const cmu = new CordovaMediaUpload({
  imageWidth: 640,
  imageHeight": 480,
  imageQuality: 50,
  videoWidth: 640,
  videoHeight: 480,
  videoBitRate: 1000000
});
[]

The error throws by calling getMedia. In getMedia the Error gets caught.
The error message is probably caused by the fact that in line 39 of your cordova-media-upload.js this.optionsObj is "undefined". Therefore, also "Unexpected token u in JSON at position 0". I can not say why it would be "undefined"…

But I could also be wrong, I haven't quite figured out your code yet.

I can't get past the error.
Please help.

@D-Marc1
Copy link
Contributor

D-Marc1 commented Nov 25, 2020

Hey @Stakdek, have you considered using CapacitorJS instead of Cordova first of all? I would highly recommend switching to Capacitor, as Cordova seems to be dying out.

As for your error, I remember getting that error when something was wrong with my AJAX call. It could also be that one of the Cordova plugins is broken.

As I stated though, switching to Capacitor is honestly the best move in my opinion. It's a much better ecosystem to work with and is basically the successor to Cordova.

@Stakdek
Copy link
Author

Stakdek commented Nov 26, 2020

Hey @D-Marc1!
The switch to CapacitorJS would not work for me…

In my code, I am not using any AJAX call, the code above is the only call it gets. The initial call is an only a Button.
Do you know which of the Cordova plugins could be broken?

The switch to CapacitorJS would escalate in work for me… so this is no option for me.

@D-Marc1
Copy link
Contributor

D-Marc1 commented Nov 26, 2020

I think it might be the VideoEditor plugin where it creates the thumbnail, specifically here. I remember when I was using Cordova there were annoyances over when I would have to append file://. It could also be this line, as I also had to append it there.

Can you try these plugins separately to confirm where the error comes from? Cordova Camera and Cordova Video Editor

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants