修改播放列表为JSON数组

This commit is contained in:
fangxiang 2022-01-21 10:20:26 +08:00
parent 0da2e1993f
commit e839e830a7
5 changed files with 80 additions and 71 deletions

View File

@ -1,6 +1,6 @@
{ {
"name": "media_player_client", "name": "media_player_client",
"version": "1.0.3", "version": "1.2.0",
"description": "A Quasar Framework app", "description": "A Quasar Framework app",
"productName": "MediaPlayerClient", "productName": "MediaPlayerClient",
"author": "fangxiang <fangxiang@cloudview.work>", "author": "fangxiang <fangxiang@cloudview.work>",

View File

@ -82,6 +82,7 @@
ref="accept" ref="accept"
flat flat
:label="$t('close and save')" :label="$t('close and save')"
:disable="play_list.length == 0"
:loading="loading" :loading="loading"
type="submit" type="submit"
color="primary" color="primary"
@ -130,68 +131,47 @@ export default defineComponent({
let _resolove: any = null; let _resolove: any = null;
const initialize_properties = (options: any) => { const initialize_properties = (playlist: string) => {
play_list.value = []; play_list.value = [];
const prefix = ( const prefix = (
GlobalData.getInstance().applicationConfig?.application_data_dir ?? "" GlobalData.getInstance().applicationConfig?.application_data_dir ?? ""
).replace(/\\/g, "/"); ).replace(/\\/g, "/");
if (typeof options == "string") {
for (let item of options.split(";")) { console.log(playlist);
if (!item || item.length == 0) { const temp_play_list = [];
continue; try {
} const temp_parse = JSON.parse(playlist);
try { if (Array.isArray(temp_parse)) {
/* try { for (const item of temp_parse) {
const url = new URL(item); temp_play_list.push(item.toString());
if (url.host == "media" && url.pathname.startsWith("/usb")) {
const usb_index = parseInt(url.pathname.substr("/usb".length, 1));
if (!isNaN(usb_index)) {
const target_path = decodeURI(url.pathname);
item =
"/usb" +
(usb_index + 1).toString() +
target_path.substr("/usb0".length);
} else {
console.error("url:", item);
console.error("url:", url);
console.error(
"usb_index:",
url.pathname.substr("/usb".length, 1)
);
console.error("usb_index:", usb_index);
}
} else if (
url.host == "userdata" &&
url.pathname.startsWith("/media_player_datas")
) {
item = decodeURI(url.pathname).substr(
"/media_player_datas/".length
);
}
} catch {}*/
let temp_str = decodeURI(new URL(item).pathname).replace(
/\\/g,
"/"
);
if (
(GlobalData.getInstance().applicationConfig?.runtime_os ??
"UNKNOW") == "WINDOWS"
) {
temp_str = temp_str.substr(1);
}
if (temp_str.startsWith(prefix)) {
temp_str = temp_str.substr(prefix.length + 1);
}
play_list.value.push(temp_str);
} catch (e) {
console.warn(e);
} }
} else {
temp_play_list.push(temp_parse.toString());
}
} catch (e) {
temp_play_list.push(playlist.toString());
}
for (let item of temp_play_list) {
if (!item || item.length == 0) {
continue;
}
try {
let temp_str = decodeURI(new URL(item).pathname).replace(/\\/g, "/");
if (
(GlobalData.getInstance().applicationConfig?.runtime_os ??
"UNKNOW") == "WINDOWS"
) {
temp_str = temp_str.substr(1);
}
if (temp_str.startsWith(prefix)) {
temp_str = temp_str.substr(prefix.length + 1);
}
play_list.value.push(temp_str);
} catch (e) {
console.warn(e);
} }
} else {
console.error("options type error!", options);
} }
}; };
@ -259,13 +239,12 @@ export default defineComponent({
try { try {
if (_resolove) { if (_resolove) {
if (play_list.value.length == 0) { if (play_list.value.length == 0) {
_resolove(""); _resolove();
} else { } else {
const temp = const temp =
GlobalData.getInstance().applicationConfig GlobalData.getInstance().applicationConfig
?.application_data_dir ?? ""; ?.application_data_dir ?? "";
console.log(temp); let temp_play_list = [];
let str = "";
for (const item of play_list.value) { for (const item of play_list.value) {
try { try {
if ( if (
@ -274,22 +253,24 @@ export default defineComponent({
) { ) {
/** windows */ /** windows */
if (item.startsWith("/")) { if (item.startsWith("/")) {
str += item + ";"; temp_play_list.push(item);
} else if (item[1] == ":") { } else if (item[1] == ":") {
// windows // windows
str += "file:///" + (item + ";"); temp_play_list.push("file:///" + item);
} else { } else {
str += new URL(temp + "/" + item).toString() + ";"; temp_play_list.push(
new URL(temp + "/" + item).toString()
);
} }
} else { } else {
/** linux */ /** linux */
str += item + ";"; temp_play_list.push(item);
} }
} catch (e) { } catch (e) {
console.log(e); console.log(e);
} }
} }
_resolove(str); _resolove(temp_play_list);
} }
} }
show_dialog.value = false; show_dialog.value = false;

View File

@ -378,6 +378,7 @@ export default defineComponent({
const requestAddSignalSource = async () => { const requestAddSignalSource = async () => {
item_data.group_uuid = selected.value; item_data.group_uuid = selected.value;
let response = await GlobalData.getInstance() let response = await GlobalData.getInstance()
.getCurrentClient() .getCurrentClient()
?.addSignalSource(item_data); ?.addSignalSource(item_data);
@ -471,11 +472,36 @@ export default defineComponent({
loading.value = false; loading.value = false;
}, },
async showPlaylistDialog() { async showPlaylistDialog() {
if (item_data.window_type != "EwindowType::Multimedia") {
return;
}
const result = await playlist_dialog.value.showDialogAsync( const result = await playlist_dialog.value.showDialogAsync(
item_data.media_url item_data.media_url
); );
if (result) { if (Array.isArray(result)) {
item_data.media_url = decodeURI(result); if (result.length) {
if (
!item_data.name ||
item_data.name.trim() == "" ||
item_data.name.trim() == $t.t("new signal source")
) {
try {
const temp_item = decodeURI(result[0].toString());
let index = temp_item.lastIndexOf("\\");
if (index == -1) {
index = temp_item.lastIndexOf("/");
}
if (index + 1 == temp_item.length) {
item_data.name = temp_item.substr(index);
} else if (index + 1 < temp_item.length) {
item_data.name = temp_item.substr(index + 1);
}
} catch (e) {
console.log(e);
}
}
item_data.media_url = decodeURI(JSON.stringify(result));
}
} }
}, },
async doSelectFile() { async doSelectFile() {
@ -492,7 +518,11 @@ export default defineComponent({
if (path && file) { if (path && file) {
item_data.media_url = path + "/" + file.name; item_data.media_url = path + "/" + file.name;
if (item_data.name.trim() == "") { if (
!item_data.name ||
item_data.name.trim() == "" ||
item_data.name.trim() == $t.t("new signal source")
) {
nextTick(() => { nextTick(() => {
item_data.name = file.name; item_data.name = file.name;
}); });

View File

@ -293,7 +293,7 @@ export default {
"close and reset": "放弃修改并关闭", "close and reset": "放弃修改并关闭",
operator_signal_source: "信号源", operator_signal_source: "信号源",
"play prev": "上一曲", "play prev": "上一曲",
"play next": "一曲", "play next": "一曲",
play: "播放", play: "播放",
pause: "暂停", pause: "暂停",
"volume up": "音量加", "volume up": "音量加",

View File

@ -187,9 +187,7 @@ export default defineComponent({
type == "EwindowType::Multimedia" || type == "EwindowType::Rtsp"; type == "EwindowType::Multimedia" || type == "EwindowType::Rtsp";
can_pause_window.value = type == "EwindowType::Multimedia"; can_pause_window.value = type == "EwindowType::Multimedia";
console.log(type);
can_next_prev_window.value = type == "EwindowType::Multimedia"; can_next_prev_window.value = type == "EwindowType::Multimedia";
console.log(can_next_prev_window.value);
} }
} else { } else {
selected_window.value = null; selected_window.value = null;