在result.html中展示服务器上视频的smb路径,可以使用以下代码:

<div>
  <a href="smb://server/path/to/video.mp4" target="_blank">Video Path</a>
</div>

当用户点击视频路径时,会自动跳转到默认的文件管理器中打开,用户可以选择使用本地播放器打开视频,但这种方式不够直接和方便。

为了实现点击视频路径调用本地播放器播放,可以使用JavaScript和浏览器插件来实现。

以下是一个简单的实现方案:

  1. 在result.html中添加一个按钮,用于启动本地播放器。
<button id="play-btn">Play Video</button>
  1. 使用JavaScript在页面加载完成后,获取视频路径,并将其存储到一个变量中。
window.onload = function() {
  var videoPath = "smb://server/path/to/video.mp4";
  // TODO: Store video path in a variable
}
  1. 当用户点击“Play Video”按钮时,使用浏览器插件打开本地播放器,并将视频路径传递给它。
document.getElementById("play-btn").onclick = function() {
  var plugin = document.getElementById("my-plugin");
  var result = plugin.PlayVideo(videoPath);
  // TODO: Handle result from plugin
}
  1. 编写一个浏览器插件,用于调用本地播放器并传递视频路径。

浏览器插件的具体实现方式因浏览器而异,可以参考各个浏览器的官方文档或者第三方插件库。以下是一个使用Chrome扩展实现的例子:

// background.js
chrome.runtime.onMessage.addListener(function(request, sender, sendResponse) {
  if (request.action == "playVideo") {
    var videoPath = request.videoPath;
    var playerPath = "C:\\Program Files\\Windows Media Player\\wmplayer.exe";
    var cmdLine = "\"" + playerPath + "\" \"" + videoPath + "\"";
    var result = chrome.runtime.sendNativeMessage("com.example.playVideo", {command: cmdLine});
    sendResponse(result);
  }
});

// manifest.json
{
  "name": "My Extension",
  "version": "1.0",
  "manifest_version": 2,
  "background": {
    "scripts": ["background.js"],
    "persistent": false
  },
  "permissions": [
    "nativeMessaging"
  ],
  "externally_connectable": {
    "matches": ["http://localhost/*"]
  },
  "nacl_modules": [
    {
      "path": "my_plugin.nmf",
      "mime_type": "application/x-nacl"
    }
  ]
}

// my_plugin.nmf
{
  "program": {
    "portable": {
      "command": "my_plugin.nexe"
    }
  }
}

// my_plugin.cc
#include <iostream>
#include <cstring>
#include <string>
#include <sstream>
#include <cstdlib>
#include <unistd.h>
#include <sys/types.h>
#include <sys/wait.h>
#include <stdio.h>
#include <stdlib.h>
#include <errno.h>
#include <fcntl.h>
#include <stdint.h>
#include <unistd.h>
#include <string.h>

#define MAX_MESSAGE_LENGTH 1024

void send_message(const char* message) {
  uint32_t length = strlen(message);
  fwrite(&length, sizeof(length), 1, stdout);
  fwrite(message, sizeof(char), length, stdout);
  fflush(stdout);
}

int main(int argc, char** argv) {
  while (true) {
    uint32_t length = 0;
    if (fread(&length, sizeof(length), 1, stdin) == 0) {
      return 0;
    }

    char* message = new char[length + 1];
    if (fread(message, sizeof(char), length, stdin) != length) {
      delete[] message;
      return 0;
    }
    message[length] = '\0';

    std::string cmdLine = message;
    std::string command = cmdLine.substr(0, cmdLine.find("|"));

    if (command == "playVideo") {
      std::string videoPath = cmdLine.substr(cmdLine.find("|") + 1);
      std::string playerPath = "/usr/bin/vlc";
      std::stringstream ss;
      ss << playerPath << " \"" << videoPath << "\"";
      std::string cmd = ss.str();
      system(cmd.c_str());
    }

    delete[] message;
  }

  return 0;
}

在这个例子中,我们使用了Chrome扩展和原生应用程序来实现调用本地播放器。用户点击“Play Video”按钮时,JavaScript代码会发送一个消息给background.js脚本,background.js脚本会调用原生应用程序my_plugin来执行播放器命令。原生应用程序会调用本地播放器来播放视频。

falsk框架下resulthtml中展示服务器上视频的smb路径点击视频路径调用本地播放器播放

原文地址: https://www.cveoy.top/t/topic/nHD 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录