-1

I simply want to get the duration of a vimeo video. I don't want to use froogaloop.

The API states: "You interact with the player by sending a serialized JSON object with postMessage() to the . The following format should be used: { "method": "methodName", "value": "value" } Omit the value key if the method requires no value.""

I tried this bit of code:

*$wrapper.find('#parpap')[0].contentWindow.postMessage(JSON.stringify('method', 'getDuration'));*

Firefox tells me: NS_ERROR_XPC_NOT_ENOUGH_ARGS: Not enough arguments [nsIDOMWindow.postMessage]

Chrome tells me: Failed to execute 'postMessage' on 'Window': Invalid target origin '' in a call to 'postMessage'.

Safari tells me: [Error] SyntaxError: DOM Exception 12: An invalid or illegal string was specified. fixVideoSize

Anyone got any advice? Thanks. :)

JonasVautherin
  • 7,297
  • 6
  • 49
  • 95
Galbota
  • 63
  • 9

1 Answers1

0

The reason of the errors is that JSON.stringify converts a single value to a json string (either string, number, object or array), you are instead passing to it two strings. What you should do is compose an object like this:

$wrapper.find('#parpap')[0].contentWindow.postMessage(
  JSON.stringify(
  {
    'method': 'getDuration'
  }
));

Know more about JSON.stringify on Mozilla Developer Network

Antonio E.
  • 4,381
  • 2
  • 25
  • 35