Melodic Streaming Platform

I currently have a client-side application built using React. I have a collection of music stored on my Google Drive that I would like to stream online continuously. I lack experience in server-side programming. Can you suggest any resources or steps I should take to create a music streaming service like this?

Answer №1

To enable audio media playback, you can use the <audio> element. One method to loop the media playback is by creating an array that contains the paths to the media resources within an object.

When the canplay event of the <audio> element occurs, call the .play() function. At the ended event, return a resolved Promise.

Pass the array to the .reduce() method initialized with a resolved Promise. Use the .then() method to call the function again once all media tracks have played.

You can also utilize a Boolean flag to prevent repeated scheduling of the function that loops the media playback of requested media resources.

const mediaPlaylist = [{
  "track": "https://example.com/audio1.mp3",
  "title": "Song 1"
}, {
  "track": "https://example.com/audio2.mp3",
  "title": "Song 2"
}, {
  "track": "https://example.com/audio3.mp3",
  "title": "Song 3"
}];

const audio = document.querySelector("audio");

const nowPlaying = audio.nextElementSibling;

const mediaTracks = ((promise, {
    track,
    title
  }) =>
  promise.then(() => new Promise(resolve => {
    audio.src = track;
    audio.addEventListener("canplay", event => {
      audio.play();
      nowPlaying.textContent = title;
    }, {
      once: true
    });
    audio.addEventListener("ended", event => {
      nowPlaying.textContent = "";
      resolve();
    }, {
      once: true
    });
  }))
);

let stopMedia = false;

const mediaLoop = (playlist = Array()) =>
  !stopMedia 
? playlist.reduce(mediaTracks, Promise.resolve()) 
  : Promise.resolve("media loop stopped");

const playMedia = () => 
mediaLoop(mediaPlaylist).then(playMedia);

playMedia()
.then(message => console.log(message))
.catch(err => {console.log(err); throw err});
<audio controls></audio>Now playing: <label></label>

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Timing issues with setInterval and setTimeout are causing them to execute at the incorrect moments

I am struggling with changing the background image using setInterval and setTimeout every x seconds. The issue I am facing is that the timer is not working as intended, causing images to change instantly instead. let images = ['background1.jpg&apo ...

The Jquery $.post method is not returning any values

When I use two $.post requests in jQuery, the second one returns an EMPTY value. This is my jQuery code: var id; $.post('page.php', {id:id}, function(data){ var stat; $.post('page.php', {stat:stat}, function(newdata){ ...

Correctly define the vm function within the Controller As scope

I am a newcomer to javascript and AngularJS. So... Maybe it's a simple question, but I've noticed two ways to define functions in javascript. In the following controllers, pay attention to "grupoCancha" and "grupoVisible" (I included the entire ...

What is the best way to implement the settimeout method in react?

I need assistance on how to effectively utilize the setTimeout() method in my code. Specifically, I am looking to trigger a click event on an element after a certain delay and execute a function afterwards. Here is the current implementation of my code: ...

Having trouble retrieving features from a QR code generated with Angularx-qrcode?

I utilized angularx-qrcode in order to create a QR code that displays data from qrInfo. However, I'm encountering the following error: ERROR TypeError: Cannot read properties of undefined (reading 'qrcElement') The code within qr-code-gener ...

Animations experiencing delays on mobile Chrome

I am currently exploring the world of website animations. I have a version of the jsfiddle code linked below that is similar to what I am working on. The animations function perfectly when viewed on desktop, but when accessed on mobile - specifically on my ...

Issue encountered while trying to update form data in mongoDB with nodejs

The post delete options are functioning correctly, but the put operation is not working as expected. It updates successfully, however with function String() { [native code] } values. controller.ts router.put('/:id', (req,res)=> { if (!Ob ...

Looking for guidelines on Node, Express, and Jade styling?

Having previous experience in PHP, I am used to using 4 spaces for tabs. However, I have noticed that in many examples and project bootstrap code, only 2 spaces are used. I have searched for definitive style guides for these projects but have not found a ...

How can I transfer data from a MySQL callback function to a global variable?

I'm still in the learning stages of using nodejs and working on getting more comfortable with it. My goal is to retrieve a user from a database and store it in a variable, but I'm having trouble storing it globally. Though I can see that the conn ...

I have a task of extracting information from a live Google map and generating a static Google map using API V3

I am working on a project that involves allowing users to create maps using Google Maps and then save the image. My current workaround uses both the Google Maps API V3 and the Static Maps API. The user can interact with the dynamic Google map by scrolling ...

Error parsing module: Encountered unexpected token at line 7855, character 112

Currently, I am in the process of constructing a frontend application using npm run build via Jenkins. Unfortunately, I have encountered an error message as shown below. Can you provide guidance on how to resolve this issue? Creating an optimized productio ...

A specific image is loading after being clicked in a new page

Despite my efforts to search on various platforms, I have not been able to find a comprehensive solution to my query. Scenario: I currently have a webpage containing a div with multiple images. These images load without any issues and are set to open in ...

URL multiplying on its own accord

Do you have any idea why my subdomain's website is suddenly duplicating its URL and giving me an error? The correct URL is , but it ends up as this . When this happens, my site appears broken, almost as if the CSS setup is not correct. ...

What is the process for redirecting to an external URL while including post parameters?

When a user accesses my endpoint, I need it to automatically redirect them to an external URL with URL-encoded form parameters. Endpoint: https://example.com Form Parameters: Name: testing ID: 123456 I have attempted the following in Express. It succes ...

To close the Muix DateTimePicker, simply hit the Escape key or click anywhere outside of the picker

I'd like the DateTimePicker to only close when the user presses the action buttons, not when they click outside or press Escape. Unfortunately, I haven't found any props to control this behavior yet. <DesktopDatePicker closeOnSelect={false} s ...

Unable to execute an Angular 2 application within Visual Studio 2015

I encountered an error while trying to set up an environment on VS 2015 with Angular2. Whenever I run the command "npm start," I receive the following error message. I attempted using "npm cache clean --force" before running "npm start," but the error pers ...

Import MDX metadata in Next.js on the fly

I am currently utilizing Next.js to create a static blog site. Following the guidelines in Next.js documentation, I set up @next/mdx and successfully imported MDX statically using import MDXArticle from "@/app/(article)/2023/test-article/page.mdx&quo ...

Browserify pulls in entire module even if only specific parts are utilized, such as react-addons

I am currently using Browserify to bundle my server-side react.js code for the client. There is a concern that utilizing a module from an npm package may result in the entire package being bundled by Browserify. Question: Will require('react-addons& ...

What is the best way to retrieve the height of the parent element in my specific situation

I am facing an issue in my directive where I need to access the height of the parent element. Here is a snippet of my code: (function(window, angular) { var app = angular.module('myApp'); app.directive('testElem', [ fu ...

execute a rigorous compilation during the ng build angular process

I am currently working on a project using angular-cli and I have configured my package.json with the following scripts: "scripts": { "ng": "ng", "build": "ng build --base-href /test/", "prod": "ng build --prod --base-href /test/" } According to the ...