Search code examples
javascripthttpvlc

VLC http remote control


I want to make a simple web interface for switching vlc player songs. It already has a built-in web server and commands for interacting with it. But when I send a GET request with the command, VLC returns 401 error. I cannot figure out how to pass the password from the VLC web interface in my request. And I can't figure out how to disable authorization.

Maybe someone has already encountered or offers an alternative way to remotely control VLC

My JS code with request

const play = document.querySelector('.play')
const pause = document.querySelector('.pause')


var xhr = new XMLHttpRequest();

play.addEventListener('click', () => {
    xhr.open('GET', 'http://127.0.0.1:8080/requests/playlist.xml?command=pl_play', false);

    xhr.send();
    console.log('click play')
})

pause.addEventListener('click', () => {
    xhr.open('GET', 'http://127.0.0.1:8080/requests/playlist.xml?command=pl_pause', false);

    xhr.send();
    console.log('click play')

})

Solution

  • To authenticate your request, you need to set a Request Header. In your case:

    xhr.setRequestHeader("Authorization", "Basic " + btoa("username:password"));