api-play button control code

• Nov 19, 2018 - 05:33

I have managed to embed my score(s) in my site using an iframe. Thank you for this feature.
I would like to capture the play button functionality so that I can make an alternate button outside of the embedded content. (this is so that user could flip through a playlist of scores without having to re-engage the native musescore playbutton for each score) / alternatively- autoplay functionality for scores?
If I could gain the code from you that is the play button only, that would assist me with this question.


A little bit of looking around with my browser inspector and it seems that within the iFrame, running jsmuseInstance.playToggle() works perfectly for driving the play/pause button

In reply to by scottwarren

Yes, it is JavaScript. Sorry, I kind of assumed someone talking about creating a play button outside of the embedded score would have some notion of the scripting involved.
If I remember correctly you should be able to add an id to the embed element; then from your parent page use that to access the document within for which the given code indeed works on global document scope. I'm not sure if this is still allowed in modern browsers, given that it can be considered as cross-domain scripting.

In reply to by jeetee

Hi guys,

I asked this question long ago.
I appreciate the replies given so far!

Apparently Jeetee was correct in Nov-18 re"cross-domain scripting".

All I'm trying to do is run play/pause from my own buttons, so that I can track user achievements. I want to gamify.

Prior to my initial post, I had this working.
Then the cross-domain scripting.rules must have kicked in.

I have now returned to the old buttons, and discovered that they actually still work -if- the iframe has literally been interacted with by the user actually clicking, even an inactive portion within the iframe.
After that, my buttons work.

So, I think I now have a more informed question. The inspector says that cookies have not been defined as "same site" "secure" or "LAX". I assume these are cookies on your end, as my site uses none.

I know little about MuseScore's cookies, but would be possible to provide a cookie that would allow this specific iteraction from my site?

It would solve my whole music-ed flow!

Thanks much!

In reply to by scottwarren

Ps -

So now I am discovering that these embeds are taking forever to load, And even besides the above,
inspector is constantly warning about "cross-domain cookies". In particular, "waiting for mc.yanex..."
Sometimes my embeds hang forever, with the "waiting for yanex" info in Chrome.

I read other "yanex" threads, and don't understanf why an embed should be involved with it.

So, it seems that MS cookies are really in the way. Can this be fixed?

In reply to by scottwarren

I'm not sure you fully grasp what an embed is; it is nothing more than a mechanism to allow one (parent) webpage to load a different webpage in a predestined area.
And that webpage that is loaded is the normal score webpage from musescore.com, which includes all its normal tracking and cookies and statistics (which is what yanex is, a russian google-stats competitor)

In reply to by jeetee

No jeetee,
I actually DO unerstand an Iframe now.
Thanks for your confirming education!
I have since found some "my bad's in my code"
BUT, my post.
is mainly in sincere attempt
to workaround "cross-domain scripting rules"
- which you had pointed out over 2 years ago.

All I want, is to allow the play/pause toggle function, from my Domain.

  • Believe-ir-not:

3 years ago, I found some code on StackOverflow, that worked - until browser-rules kicked in.
Now, I have managed to reconstruct that code, (blindly) to still work! Yay!

Only prob, is (like a musical "pickup", I have to -for some reason - trick my users to manually
click the iframe object first,
or the transport freezes -in place- without playing.

If only, that step could be avoided!

Where I began discussion of "cookies", is that the CDS rules seem to be patrolled
in browser functions, BY "cookies". (Going by inspector warnings and complaints)

I cannot takeover your site domain, by mine, - thankfully!
Just hoping for a way to allow my mere buttons to toggle play/Pause, on Your end.

Thanks for you reply!

In reply to by scottwarren

As you by now are likely aware (from your other topic as well); nobody in these forums can do/change anything about the .com online score sharing platform. It is run by a different entity/team.

You say your current code works as long as the user puts the focus into the iframe first. Isn't that perhaps something you could trigger somehow as well. Something in the line of document.getElementById("myIframe").focus() ?

In reply to by jeetee

Thank you
jeetee !!


Somehow the allow="autoplay; parameter was missing!

Now I can move forward!

(I was hungup on the Browser "Cross Domain Rules", thinking I had to defeat them).

That's all it was.

So I now understand that there is a .org/and .com for musescore,
and what Ithink you guys are saying, is that you have no control of "embed" functionality?
-Why I see very little related discussion here?-

Anyway, I am a happy camper, and your effort has helped make that so.


In reply to by scottwarren

That is in the Share > Embed dialog on a score on musescore.com

<iframe width="100%" height="394" src="https://musescore.com/user/xxx/scores/yyy/s/zzz/embed" frameborder="0" allowfullscreen allow="autoplay; fullscreen"></iframe>
<span><a href="https://musescore.com/user/xxx/scores/yyy/s/zzz" target="_blank">Title</a> by <a href="https://musescore.com/user">User</a></span>

In reply to by Jojo-Schmitz

i Know! Jojo, but somehow that parameter got ommitted from my prototype. upon modifications
For others, good to know, - but when I began this thread, the Browser CrossDomainScripting rules had just begun enforced,
And so I got lost in that desert, with respect to Jeetee's accurate disclaimer initially.

Sorry for my bad.


Do you still have an unanswered question? Please log in first to post your question.