Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8935131
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T09:55:38+00:00 2026-06-15T09:55:38+00:00

I have a small self-written web-server, that is capable of processing POST\GET queries. Also,

  • 0

I have a small self-written web-server, that is capable of processing POST\GET queries. Also, I have a Handler, that receives audio files and puts them in the response stream, like that:

package com.skynetwork.player.server;

import ...

public class Server {
private static Logger log = Logger.getLogger(Server.class);
//Here goes the handler.
static class MyHandler implements HttpHandler {
    private String testUrl = "D:\\test";
    private ArrayList<File> urls = new ArrayList<File>();

    private long calculateBytes(ArrayList<File> urls) throws IOException {
        long bytes = 0;
        for (File url : urls) {
            bytes += FileUtils.readFileToByteArray(url).length;
        }
        return bytes;
    }

    public void handle(HttpExchange t) throws IOException {
        File dir = new File (testUrl);
        System.out.println(dir.getAbsolutePath());
        if (dir.isDirectory()) {
            log.info("Chosen directory:" + dir);
            Iterator<File> allFiles = (FileUtils.iterateFiles(dir, new String[] {"mp3"}, true));
            while (allFiles.hasNext()) {
                File mp3 = (File)allFiles.next();
                if (mp3.exists()) {
                    urls.add(mp3);
                    log.info("File " + mp3.getName() + " was added to playlist.");
                }
            }                       
        } else {
            log.info("This is not a directory, but a file you chose.");
            System.exit(0);
        }

        t.sendResponseHeaders(200, calculateBytes(urls));
        OutputStream os = t.getResponseBody();
        for (File url : urls) {
            os.write(FileUtils.readFileToByteArray(url));
        }
        os.close();
    }
}

public static void main(String[] args) throws Exception {
    HttpServer server = HttpServer.create(new InetSocketAddress(8080), 0);

    server.createContext("/test", new MyHandler());
    server.setExecutor(null); 
    server.start();
}


}

Right now it takes all of the audio files and creates one solid stream. I would like it to play in loop infinitely, like a small radio station in the web. So when my server is running, I enter a url in the browser and it plays the audio files from the directory in loop.

EDIT:

If my server has the needed bytes, how could I play these bytes in a loop, for example in VLC Player?
I mean it will play the stream just once, but how could I loop it?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-15T09:55:40+00:00Added an answer on June 15, 2026 at 9:55 am

    Hello Constantine i think it’s important to understand the difference between progressive download and streaming here.
    What you are doing is not streaming at all but a progressive download, that is to say you have to download first if you want to jump to that part of the file (ex. You Tube) while in streaming that’s not necessary and you can listen to it endlessly (ex. BBC Radio)

    I would recommend you to check out the red5 server project in you are interested in streaming.

    If you want to go on with your present code (progressive) perhaps you should just create an never ending output stream and pause every now and then to limit the download speed.

    I hope this helps!

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have small web app that generate PDF files as a report. I'm trying
I have a server written ( self written - no Tomcat or Jetty )
I have written a few small utility applications in Clojure that I compile into
I have written a small wrapper for the dict built-in class that loads entries
I have a small self made gallery which im still working on it: http://springbreak.enteratenorte.com
I think the title is self-explanatory. Many times I have small typos and I
I have a small app that from the home screen has a few buttons,
i have written a small grails webapp. I am using milton.io to access some
I have written some code that uses attributes of an object: class Foo: def
Possible Duplicate: Self-references in object literal declarations Hey Guys, i have a small question

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.