Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/315.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 无法在我自己的服务器提供的chrome中查找音频文件_Java_Google Chrome_Html5 Audio - Fatal编程技术网

Java 无法在我自己的服务器提供的chrome中查找音频文件

Java 无法在我自己的服务器提供的chrome中查找音频文件,java,google-chrome,html5-audio,Java,Google Chrome,Html5 Audio,我正在尝试用Java制作一个文件服务器,它可以提供可查找的音频文件。但我提供的文件在谷歌Chrome html5音频播放器中不可见。当我向前搜索时,它什么也不做(即使是下载的内容),如果向后搜索太多,它会从头开始。如果我从不同的位置()加载文件,那么它是可查找的 这是我的服务器代码 package com.company; import com.sun.net.httpserver.Headers; import com.sun.net.httpserver.HttpExchange; imp

我正在尝试用Java制作一个文件服务器,它可以提供可查找的音频文件。但我提供的文件在谷歌Chrome html5音频播放器中不可见。当我向前搜索时,它什么也不做(即使是下载的内容),如果向后搜索太多,它会从头开始。如果我从不同的位置()加载文件,那么它是可查找的

这是我的服务器代码

package com.company;

import com.sun.net.httpserver.Headers;
import com.sun.net.httpserver.HttpExchange;
import com.sun.net.httpserver.HttpHandler;
import com.sun.net.httpserver.HttpServer;

import java.io.*;
import java.net.InetSocketAddress;


public class Main {

    public static void main(String[] args) throws Exception {
        HttpServer server = HttpServer.create(new InetSocketAddress(8000), 0);
        server.createContext("/Epoq-Lepidoptera.ogg", new MyHandler());
        server.setExecutor(null); // creates a default executor
        server.start();
    }


    static class MyHandler implements HttpHandler {
        public void handle(HttpExchange httpExchange) throws IOException {

            long contentLength;
            File file = new File("Epoq-Lepidoptera.ogg");
            FileInputStream fis = new FileInputStream(file);
            BufferedInputStream bis = new BufferedInputStream(fis);
            contentLength = file.length();
            System.out.println(contentLength);

            Headers headers = httpExchange.getResponseHeaders();
            headers.add("content-type", "audio/ogg");

            // ok, we are ready to send the response.
            httpExchange.sendResponseHeaders(200, contentLength);
            OutputStream os = httpExchange.getResponseBody();
            byte[] data = new byte[1000];
            while (true) {
                int bytesRead = bis.read(data);
                if (bytesRead == -1) break;
                os.write(data, 0, bytesRead);
            }

            os.close();
            System.out.println("request served");
        }
    }
}
我使用这个html文件来测试音频

<html>
    <body>
        <audio controls="control" preload="auto" src="http://localhost:8000/Epoq-Lepidoptera.ogg"></audio>
    </body>
</html>

但下面的文件是可查找的

<html>
    <body>
        <audio controls="control" preload="auto" src="http://www.vorbis.com/music/Epoq-Lepidoptera.ogg"></audio>
    </body>
</html>

我做错了什么,或者我应该在我的服务器中实现什么,以使文件可查找,下载内容最少(以白色条显示)


这个问题只是谷歌浏览器的问题,而不是火狐浏览器的问题。Firefox可以搜索加载的内容。

相关:不相关,因为现在我们使用带有音频标签的html5。在链接主题示例中,使用jPlayer(flash).Related:notrelated,因为现在我们使用带有音频标签的html5。在链接主题示例中使用jPlayer(flash)。