Dynamic data change in js() in .kt


I am completely new to JS and Kotlin/JS, so be kind :slight_smile:

So, I have a custom JS file and function like this:

function playUrl(url) {
var options = {};
var player = videojs(‘my-video_html5_api’, options, function onPlayerReady() {
player.src({ type: ‘application/x-mpegURL’, src: url});

I would like to call this function in the main .kt class as


this js() doesn’t allow to change string dynamically, so I need help on how to overcome this issue.

If I hardcode myURL it will work, but I need to change it on keyboard actions (up, down. etc.)

I have imported all needed files (JS files) in main html page as

Demo WEB app

Hi there,

you don’t need to use js() for that, you can declare playURL() as an external function and then call it properly in your Kotlin code : Use JavaScript code from Kotlin | Kotlin


Thanks, it works very well.

Also if you really really wanted to use a dynamic js() call for this, you can do js("playUrl($myUrl)") since the dollar sign makes it use string interpolation which then grabs the value of myUrl and calls playUrl with it

js() function doesn’t allow interpolation, only static string.