Close
0%
0%

Raspberry PI FLAC audio server

Do you have a bunch of FLAC files, and want to enjoy the music on any device on your network? NO APP REQUIRED! :)

Public Chat
Similar projects worth following
There was a request from the boss (not Neil Young, but close), to be able to play high quality audio (FLAC) anywhere and on any reasonable device on our network, without an app.

Follow the steps to set up your own little server on your home network.  Then, without any app, just point your device browser to the raspberry pi, and listen to the audio file (flac, mp3, etc.).


Look to the steps - I included the structure of the JSON and the fully commented website code (all in one nice HTML file).

Here is the view off of an IOS device.  You know what is cool?  You can play music through the browser with your phone locked.  The HTML code will keep playing the album on loop.

Here is a photo of the Raspberry PI with the micro sd reader and card.

  • 1 × Raspberry PI
  • 1 × SanDisk MobileMate USB 3.0 microSD Card
  • 1 × Micro SD card

  • Updated the HTML - now loads simpler JSON file

    sciencedude199005/15/2021 at 03:25 0 comments

    This new version of the HTML will load a simpler JSON file - one that can have line breaks...it uses a XMLHttpRequest() to load the simple JSON text file...

    The new file format can be

    [{},

    {},

    {},

    ...

    ]

    Here is the HTML:

    <html>

    <link rel="icon" 
          type="image/png" 
          h r e f = " your url / favicon.png ">
    <title>Music Catalog</title>
    <style>
    #myUL {
      /* Remove default list styling */
      list-style-type: none;
      padding: 0;
      margin: 0;
    }

    #myUL li a {
      border: 1px solid #ddd; /* Add a border to all links */
      margin-top: -1px; /* Prevent double borders */
      background-color: #f6f6f6; /* Grey background color */
      padding: 12px; /* Add some padding */
      text-decoration: none; /* Remove default text underline */
      font-size: 40px; /* Increase the font-size */
      color: black; /* Add a black text color */
      display: block; /* Make it into a block element to fill the whole list */
    }

    #myUL li a:hover:not(.header) {
      background-color: #eee; /* Add a hover effect to all links, except for headers */
    }
    </style>
    </head>
    <body onload="init()">

    <script>

    var album_start = -1;
    var album_stop  = -1;
    var album_current = -1;
    // The Audio player
    var theAudio;
    // Parse the JSON file
    var mydata; 
    // The main list
    var the_UL;
    // Text about the song
    var theText;

    function init() {
    theAudio = document.getElementById("myAudio");

    // Create XMLHttpRequest
            var xmlhttp = new XMLHttpRequest();

            // When ready, try to read the filenames from the file
            xmlhttp.onreadystatechange = function() {
                if (this.readyState == 4 && this.status == 200) {
                    // Parse it 
                    //console.info(this.responseText);
     
                    mydata = JSON.parse(this.responseText);
                }
            };

            // Set the name of the file
            xmlhttp.open("GET", "new_catalog.json", true);
            // The send
            xmlhttp.send();

    the_UL = document.getElementById("myUL");
    theText = document.getElementById("myText");

    theAudio.onended = function() { nextSongandPlay();};

    theAudio.setAttribute("style", "width:" + (window.innerWidth - Math.round(window.innerWidth * 0.03)) + "px");
    }

    function nextSongandPlay() {
    // When a song in the album finishes play, get the next song...
    if ((album_current + 1) > album_stop) {
    playSong(album_start);
    }
    else {
    playSong(album_current + 1);
    }

    }

    function loadAudio() {
    theAudio.src = mydata[album_current].filename;

    theText.innerHTML = mydata[album_current].Title + ", " + mydata[album_current].Artist;
    }

    function loadSingleAlbum(ii) {
    // Clear UL
    clearUL();

    if (mydata.length >= 1) {
    if ((ii >= 0) && (ii < mydata.length)) {
    // Start at ii and find the maximum ii
    var ii_max = ii;

    var found_it = 0;

    while (found_it == 0) {
    if (ii_max == (mydata.length - 1)) {
    // At the end of the list, stop
    found_it = 1;
    }
    else {
    if (mydata[ii_max + 1].Album.localeCompare(mydata[ii].Album) != 0) {
    // Next item in list is not in album
    found_it = 1;
    }
    else {
    // Keep searching
    ii_max = ii_max + 1;
    }
    }
    }

    // Great - add the songs to the main list
    for (jj = ii; jj <= ii_max; jj++) {
    addItemSong(mydata[jj].Track + " " + mydata[jj].Title, jj);
    }

    // Set album start and stop
    album_start = ii;
    album_stop = ii_max;
    album_current = ii;

    // Load the audio
    loadAudio();

    // Bring the browser back to the top of the page
    window.scrollTo(0, 0);
    }
    }
    }

    function loadAlbums() {
    // Stop the player
    theAudio.pause();
    theAudio.src = "";
    theText.innerHTML = "Welcome";

    // Clear the UL
    clearUL();
        
    // Place the JSON contents in UL
    if (mydata.length >= 1) {
    var go_add = 1;
    for (ii = 0; ii...

    Read more »

  • Audio CD to FLAC, VLC media player

    sciencedude199004/07/2021 at 12:12 0 comments

    VLC Media Player has the capability to create FLAC files from an audio CD.  It has "lua" scripting.  So, place the script below into the directory:

    VideoLAN\VLC\lua\extensions

    Then, in the View menu, you'll see a new option called "Audio CD to flac".  Enter the number of Tracks in the track field, then press Apply profile, and then press Enqueue converting tracks.

    Now, the CD to flac conversion will be in your play list - so click View -> Playlist, and then press the big play button.  The CD will be converted to flac files, and placed in your C:\temp directory.

    Here is the listing of the lua script (you could call it cd_flac.lua - is is based off of the post at   https://forum.videolan.org/viewtopic.php?f=29&t=130354    ):

    profiles={
    {"Audio CD -> flac", " :cdda-track=? :sout=#transcode{vcodec=none,acodec=flac,ab=128,channels=2,samplerate=44100}:file{mux=flac,dst=\"C:\\temp\\Track ?.flac\"}"},
    }

    -----

    function descriptor()
    return {
    title = "Audio CD to flac",
    capabilities={},
    }
    end

    function activate()
    create_dialog()
    end

    function deactivate()
    end

    function meta_changed()
    end

    function close()
        vlc.deactivate()
    end

    -----

    function create_dialog()
    d = vlc.dialog(descriptor().title)
    d:add_label(string.rep(" ",50),1,1,1,1)
    d:add_label(string.rep(" ",50),2,1,1,1)
    d:add_label(string.rep(" ",50),3,1,1,1)
    d:add_label(string.rep(" ",50),4,1,1,1)
    d:add_label(string.rep(" ",50),5,1,1,1)
    ----
    d:add_label("Source MRL: ",1,1,1,1)
    ti_mrl = d:add_text_input("cdda:///D:/",2,1,1,1)
    d:add_label("(Media > Open Disc... > Audio CD)",3,1,2,1)

    d:add_label("Tracks: ",1,2,1,1)
    ti_tracks = d:add_text_input("15",2,2,1,1)
    d:add_label("Then ? in output string represents the counter.",3,2,2,1)

    d:add_label("Output options: \\ Profiles:",1,3,1,1)
    dd_profile = d:add_dropdown(2,3,1,1)
    for i,v in ipairs(profiles) do
    dd_profile:add_value(v[1],i)
    end
    d:add_button("Apply profile", click_Profile, 3,3,1,1)
    d:add_label("(Media > Stream... wizard)",4,3,1,1)

    ti_sout_string = d:add_text_input(profiles[1][2], 1,4,5,1)

    d:add_button("Enqueue converting tracks", click_Convert, 2,5,1,1)
    d:add_label("Then start the 1st converting track in playlist (View > Playlist).",3,5,2,1)
    end

    function click_Profile()
    ti_sout_string:set_text(profiles[dd_profile:get_value()][2])
    end

    function click_Convert()
    local j=tonumber(ti_tracks:get_text())
    if not j then j=1 ti_tracks:set_text(j) end
    local source_string = ti_mrl:get_text()
    local options_string = ti_sout_string:get_text()
    local table_items={}
    table.insert(table_items,{path="vlc://pause:3", name="[Convert! START]", options={}})
    for i=1,j do
    table.insert(table_items,{path=source_string, name="[Convert!] Audio CD - Track "..i, options=SplitString(string.gsub(options_string,"%?",i), " :")})
    end
    table.insert(table_items,{path="vlc://pause:3", name="[Convert! END]", options={}})
    vlc.playlist.enqueue(table_items)
    end

    -----

    function SplitString(s, d) -- string, delimiter pattern
    local t={}
    local i=1
    local ss, j, k
    local b=false
    while true do
    j,k = string.find(s,d,i)
    if j then
    ss=string.sub(s,i,j-1)
    i=k+1
    else
    ss=string.sub(s,i)
    b=true
    end
    table.insert(t, ss)
    if b then break end
    end
    return t
    end

View all 2 project logs

  • 1
    Connect the raspberry pi

    Connect the raspberry pi to your home router with an ethernet cable.  Set a static ip address on the PI.

    At the prompt:

    sudo nano /etc/dhcpcd.conf

    Add the following lines for at the bottom of the file:

    interface eth0

    static ip_address=192.167.1.106/24

    static routers=192.167.1.1

  • 2
    Install the webserver

    Install your favorite webpage server, such as:

    https://www.raspberrypi.org/documentation/remote-access/web-server/apache.md

    Make a subdirectory in the html folder, call it "music"

    i.e.,

    /var/www/html/music

  • 3
    Connect the SD card

    Nothing is better than a giant capacity micro SD card to store all your music!

    Connect it to the PI, then figure out where it went...

    Use the command

    sudo lsblk -o UUID,NAME,FSTYPE,SIZE,MOUNTPOINT,LABEL,MODEL

    The result will give something like this...

    UUID                                 NAME    FSTYPE  SIZE MOUNTPOINT LABEL MODEL

                                         sda            29.7G                  SDDR-

                                             sda1  vfat   29.7G 

    ...

    It is probably called sda1.

    Now, you are going mount the drive in the music folder...

    Edit your rc.local file...

    sudo nano /etc/rc.local

    Add at the end of the file add..

    mount /dev/sda1 /var/www/html/music

View all 6 instructions

Enjoy this project?

Share

Discussions

Similar Projects

Does this project spark your interest?

Become a member to follow this project and never miss any updates