Uploaded image for project: 'Apache Cordova'
  1. Apache Cordova
  2. CB-9780

Failed to execute 'play' on 'HTMLMediaElement': API can only be initiated by a user gesture.

    XMLWordPrintableJSON

    Details

      Description

      I am using the below code to click picture on click of a button i call handleMediaDialog() with options

              function optionsForType(type) {
                  var source;
                  switch (type) {
                      case 0:
                      source = Camera.PictureSourceType.CAMERA;
                      break;
                      case 1:
                      source = Camera.PictureSourceType.PHOTOLIBRARY;
                      break;
                  }
                  return {
                      destinationType: Camera.DestinationType.FILE_URI,
                      sourceType: source,
                      allowEdit: false,
                      encodingType: Camera.EncodingType.JPEG,
                      popoverOptions: CameraPopoverOptions,
                      saveToPhotoAlbum: false
                  };
              }
      
              function handleMediaDialog(type) {
                  return $q(function(resolve, reject) {
                      var options = optionsForType(type);
      
                      Camera.getPicture(options).then(function(imageUrl) {
                          //convert url to where file is saved
                          if (imageUrl.substring(0,21)=="content://com.android") {
                              photo_split=imageUrl.split("%3A");
                              imageUrl="content://media/external/images/media/"+photo_split[1];
                          }
      
      
                          // if image doesnt has extention like in case of whatsapp we add jpg
                          var name = imageUrl.substr(imageUrl.lastIndexOf('/') + 1);
                          if(name.indexOf('.') === -1) {
                              name = name + ".jpg";
                          }
      
      
                          //convert content:// to file:///
                          var newName = makeid() + name;
                          $cordovaFileTransfer.download(imageUrl, cordova.file.dataDirectory + newName, {}, true).then(
                              function(fileEntry) {
                                  //FileService.storeImage(fileEntry.nativeURL);
                                  resolve(fileEntry.nativeURL);
                              }, function (error) {
                                  reject(error);
                              }
                          );
                      });
                  })
              }
      

        Attachments

          Activity

            People

            • Assignee:
              TimBarham Tim Barham
              Reporter:
              awebdeveloper Prathik S
            • Votes:
              0 Vote for this issue
              Watchers:
              1 Start watching this issue

              Dates

              • Created:
                Updated: