I do know how to solve the language/audio issue, but I don't know how to put it together as code

D.Sof

This is my code:

$(document).ready(function() {
$(document).on("click", ".audioButton", function() {
var word = $(this).parent().find('.exerciseWord').html().toLowerCase() + '.mp3';
play(word);
});
getFileArray(); // load on page load
});

function getFileArray(word) {
$.getJSON("https://test.diglin.eu/api/media/fileList", {
  lang: param
  })
  .done(r => {
  audioArray = r.audio;
  console.log("audio data loaded");
  if (word) play(word);
  });
}

function play(word) {
 if (!audioArray) getFileArray(word);
 else {
var foundID = audioArray.lowercase.indexOf(word);
console.log("foundID", foundID);
if (foundID > -1) {
  var audio = new Audio();
  audio.src = 'http://test.diglin.eu/' + audioArray.path + audioArray.files[foundID];
  audio.play();
   }
  }
}

The code I am trying to give to param:

$.getJSON('json_files/jsonData_' + ID + '.json', function(json) {

 var jsonDataLanguage = json.main_object.language;
}

how the JSON (with a unique ID) looks like:

{
"main_object": {
"id": "new",
"getExerciseTitle": "TestToConfirm",
"language": "nl_NL",
"application": "lettergrepen",
"main_object": {
  "title": "TestToConfirm",
  "language": "nl_NL",
  "exercises": [
    {
      "word": "Hallo Marja.",
      "syllables": [
        "hallo",
        "marja",
        "",
        ""
      ]
    }
  ]
},
"dataType": "json"
}
}

So the next thing should happen (but doesn't work when I try so):

I try to access the desired ID in my json file. There in my JSON file I have sent a language with aswell, and it should fetch that language and be the value of param. I tried doing so, but it throws the error: "json is not defined". Most likely because I am not accessing a JSON file with a certain ID. how could I do this? I know this is the problem, but I don't know how to solve it.

Chris G

Here's the code, with everything not relevant to the error removed. First, the button click handler is assigned, which takes the word and tries to play the corresponding audio. If the audio array isn't loaded yet, getFileArray is called, then the audio is played in the done callback.

If more is to be done, it is advised to move the done() code into a separate function.

EDIT: fixed request format

EDIT2: added 2nd request

var audioArray;
var LANGUAGE, WORDS, audioArray;

$(document).ready(function() {
  $(document).on("click", ".audioButton", function() {
    var word = $(this).parent().find('.exerciseWord').html().toLowerCase() + '.mp3';
    play(word);
  });
  getFileArray(); // load on page load
});

function getFileArray(word) {
  $.getJSON('jsonLanguage/language.json').done(response => {
    LANGUAGE = response.main_object.language;
    WORDS = response.main_object.exerciseGetWordInput;
    $.post("https://test.diglin.eu/api/media/fileList", {
        language: LANGUAGE
      })
      .done(r => {
        audioArray = r.audio;
        console.log("audio data loaded");
        if (word) play(word);
      });
  });
}

function play(word) {
  if (!audioArray) getFileArray(word);
  else {
    var foundID = audioArray.lowercase.indexOf(word);
    console.log("foundID", foundID);
    if (foundID > -1) {
      var audio = new Audio();
      audio.src = 'http://test.diglin.eu/' + audioArray.path + audioArray.files[foundID];
      audio.play();
    }
  }
}

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

I don't know how to use JPQL [AND] and [OR]

I'd like to paint an area but i don't know how to

python cPickle.PicklingError: Can't pickle <type 'instancemethod'> .I know the reason, but I don't know how to solve it

Ruby grammar problem . I don't know how to solve it

I don't know what to do with my Number Guess Code

I don't know how to do the same using parquet file

I just wanted add tutorial in my poor code and I wanted place help but i don't know how to do it, any idea?

I have the following errors appearing on my code, I don't know what they mean neither know how to fix them

I don't know how to fix this

I want to use AND grep operation, but i don't know how

I don't know how to make this function

How do I know if transaction code succeeded?

I found the reason for the mistake but I don't know how to solve it

I'm counting answers and I don't know how to automate this

When I try to add a Object into an ArrayList, it add the hashcode, don't know how to solve. Beginner

I want to make if else in php but i don't know how

My page number display has bugs, I know why and where but I don't know how to solve them (PyQt)

C++ C26495 warning shows up but I don't know how to solve

I don't know how can I solve OpenCV Python problem

How can I solve this if condition — I don't know where the problem is in this case?

React does not render the components - I figured out the issue, but I don't know how to fix it

An empty for loop fixed my code but I don't know how

How do I know if the code below is correct?

Python beginner. I don't know how to solve this error occurred with the code below:TypeError: '>' not supported between instances of 'str' and 'float'

I don't know how it is an unmatched )

I don't know how to do

SyntaxError: invalid syntax, I don't know how to fix this code. What's wrong with it? And how to solve it?

I have a problem with UnhandledPromiseRejection don't know how to solve it

Issue with BaseX XQuery content:unable to add an attribute, and I don't know how to add tags, just know how to add values