Many users of the KODI Media Center, part of the RetroOrangePi, have probably noticed that they use an external MPV player, which, unlike the regular player, has support for hardware decoding. This allows you to play 1080P content without lags, but there is a big problem - the only way to control the player is the keyboard. Moreover, the player doesn’t have even a minimal GUI, so what is the duration of the movie you are watching, and how much is left to the end - alas, you don’t know.
I confess that I am a very lazy person, and it’s also not very convenient to carry the keyboard along with me, considering that KODI itself is controlled from the phone. Googling a couple of minutes, I was surprised to learn that there are no ready-made solutions for remote control of MPV from a smartphone. Well, what to do - you have to write yourself. By the way, as it turned out, in the center of Vitebsk, to buy an inexpensive wireless keyboard for 1 hour of the lunch break is another quest.
MPV supports several scripting languages, one of them is Lua. On Github, I found a
mpv-network-commands project written in Lua that allows you to control a minimum of MPV functions using commands sent via UDP. After making sure that it works, during the lunch break I wrote the simplest application that implemented the most primitive functionality - in fact, it allowed you to pause, start playback from pause and close the player.
It looked like this.
')
To be able to rewind the video, as well as see the progress bar, I had to modify the original script by adding the following function:
function send_name() local title =mp.get_property("media-title"); local length = math.floor(mp.get_property("length")); local pos=math.floor(mp.get_property("time-pos")); conn_up:sendto(title.."$"..length.."$"..pos, "192.168.100.168", 756); end
The funniest thing is that the code processing incoming data from the phone turned out to be much more cumbersome:
And this is without a timer code. thread { // this thread receives incoming massages from MPV and updates views accordingly to received info try { chnl.socket().bind(InetSocketAddress(756)) chnl.configureBlocking(false) var timerStarted: Boolean = false var timer = Timer() while (true) { var buf = ByteBuffer.allocate(1024) buf.clear() var last_pos = "" if (!timerStarted) { timer = Timer() timer.schedule(myTimerTask(textView5, textView6, textView4, seekBar3), 2000, 1000) //this timer will clear views, if no info received in last 2 seconds timerStarted = true } if (chnl.isOpen) { if (chnl.receive(buf) != null) { if (timerStarted) { timer.cancel() timerStarted = false } var data_length = buf.position() buf.flip() var str = String(buf.array(), 0, data_length, UTF_8) Log.d("received data", str) val arr = str.split("$") if (arr.size >= 3) { media_length = arr[1].toInt() runOnUiThread { if (textView4.text != arr[0]) textView4.text = arr[0] if (last_pos != arr[1]) { last_pos = arr[1] textView6.text = convertSecsToFullTime(last_pos) } if (!blockview) { textView5.text = convertSecsToFullTime(arr[2]) seekBar3.max = arr[1].toInt() seekBar3.progress = arr[2].toInt() } } } } } } } catch (e: Exception) { runOnUiThread { Toast.makeText(this, e.message, Toast.LENGTH_SHORT).show() } Log.d("In MPVremote", e.message.toString()) } }
The result is this:
Source codes, and also apk, lie on
Gitkhab .
Immediately I warn you - there
may be some bugs.
The main disadvantage is that you need a fixed IP for the phone on your local network where OrangePi is running. It is necessary for the script to know where to send information about the file being played. The easiest way is to specify in the settings of your router's DHCP server to issue the same IP devices with the phone's MAC address.
Also, there are no security elements - any user on your network will be able to pause or close the player, knowing the IP media center. True, to find out what is being reproduced and whether it is being reproduced at all - no.
By the way, the use of data exchange via UDP without any confirmations creates a side effect - since receiving incoming data from the player is spinning in a separate stream, you can pause / remove the pause and close the player, even if you did not specify the correct IP of your phone to the server script. The main thing is that you know the IP of your media center.
InstallationGo to Desktop RetroOrangePi. First you need to install Lua and LuaSocket.
sudo apt-get install lua5.1 luasocket
Then go to the /home/pi/.config/mpv/ directory and create the lua directory there.
In lua, copy server.lua.
Open server.lua with the same nano and in line
conn_up:sendto(title.."$"..length.."$"..pos, "192.168.100.168", 756);
replace the IP address with the address of your phone.
Save and restart OrangePi.
Install the application on the phone. The collected apk lies on Github. Run it, go to Settings. Set there the IP of your media center and port 755. Click Save.
Everything can be used.