I wanted to use the same playlist for music files on the NAS on both PC and Android.
This time, create it with "xspf" of the playlist file with VLC.
Even if I create a playlist on my PC and use it on Android as it is, I get an error saying "The location file: /// cannot be played" and cannot use it.
As a result of various investigations, if the file path of the playlist is set to ** relative path **, it can be opened on both PC and Android.
Create a folder to save the playlist At this time, if you make the target file as close as possible to the location, it will be easier to think about the relative path when rewriting the file later.
Load the video file into VLC on your PC by dropping and dragging
Save the playlist
Open the saved playlist and rewrite it to a relative path Since there is a lot of rewriting here, I will do it with a script etc.
Will be available on PC and Android
Very convenient
When I open "xspf" created on the PC, the file path is written as "absolute path", so I decided to use Python to rewrite it as "relative path".
The path before rewriting in "xspf" is `ʻE: // music / album 01 / music.mp3, and if you make this a relative path at the above folder location,
../ album 01 / It becomes music.mp3``.
This time, the file path is `ʻE: // ``, but if you rewrite it for the same with ** shared IP address **, you can use it as it is.
So, create the following Python in ** Playlist folder ** and execute it to rewrite it to a relative path.
import shutil
import os
from pathlib import Path
def replace(file_path):
file_name = file_path
#Creating a backup file
print('path: ', file_path)
back_name = str(file_name) + '.bak'
print('back_name: ', back_name)
shutil.copy(file_name, back_name)
with open(file_name , encoding=`utf-8`) as f:
data_lines = f.read()
#String replacement
# 「["When"]""%5B"When"%If you do not replace it with "5D", "vlc":It becomes "nop" and does not load
data_lines = data_lines.replace('file:///E://music/', '../').replace('[', '%5B').replace(']', '%5D')
#Save with the same file name
with open(file_name, `w`, encoding=`utf-8`) as f:
f.write(data_lines)
#Get the folder where your py is
p_temp = os.path.dirname(__file__)
#Get a list of xspf files in a folder
for f in Path(p_temp).glob(`**/*.xspf`):
replace(f)