Welcome, Guest: Register On Nairaland / LOGIN! / Trending / Recent / New
Stats: 3,155,491 members, 7,826,844 topics. Date: Monday, 13 May 2024 at 09:35 PM

Want To Create A Music Playlist Using PHP, Ideas Pls - Programming - Nairaland

Nairaland Forum / Science/Technology / Programming / Want To Create A Music Playlist Using PHP, Ideas Pls (1908 Views)

How To Add Up Tables Using Php / What Do You Think About Using PHP For Software Development / Web Development And Programming Using PHP/MYSQL Database At Yemlat (2) (3) (4)

(1) (Reply) (Go Down)

Want To Create A Music Playlist Using PHP, Ideas Pls by cbrass(m): 11:43pm On Jun 20, 2016
I want the songs in a folder on the server then I can randomly play them to the user as a radio station. My question is how do I pick the songs without page refresh, OK we will use Ajax... but how will Ajax know the song has finished playing and should pick another
Re: Want To Create A Music Playlist Using PHP, Ideas Pls by CodeHouse: 6:57am On Jun 21, 2016
Here..

Re: Want To Create A Music Playlist Using PHP, Ideas Pls by CodeHouse: 7:03am On Jun 21, 2016
Some lines missing in first screen shot..

Re: Want To Create A Music Playlist Using PHP, Ideas Pls by teampregar(m): 9:29pm On Jun 21, 2016
CodeHouse, You be babanla or baba for the codes ohh..U too much.. Well OP, here is my suggestion , Your service will only work well if your market are users of desktop,tablet devices only, Because for smartphones na only default browser and google chrome dey support ajax without refreshin pages, the rest browsers like opera mini, uc web, dey refresh pages for ajax .. And most africans like dnt like using default browsers..

Then for the business logic, see how e go work..
Prerequiesties: You need to learn ajax and how to use the audio Html 5 node with DOM and javascript..
Code the media player, mediaGetter.js, and mediaController.php or whatever programming language and mediaReturner.php.
//Since u said songs go play randomly..
Here is my recipi and media player cycle :
START
-Onclick of start radio button: mediaGetter.js should use ajax to connect to mediaReturner.php with a parameter ?cursor=new
-mediaReturner.php should connect to mediaController.php
, get the value of the cursor parameter ,ie, $_GET(cursor),
assign a variable to the mediaControl function in mediaController.php file with the get value as an argument, ie, $song = mediaControl($_GET(cursor)); .
-on return of a value from mediaControl function ,
do this, header(" Content-Type : audio/mp3 "wink ;
echo $song;
-do the onreadystatechange ajax stuff then u, createElement(audio) ; den assign ajax.responsrText to the src attribute of the audio tag u created, then also assign the
function mediaGetter(//song name) to onafterplay event atrribute to d audio tag.
-Onafterplay: if this attribute is added to the audio tag when the music finishes playing it will recall the mediaGetter function to get another song.

Here is how mediaControl in mediaController.php function works:

function mediaControl($a)
if($a=='new')
//get ur music directory as a string
use list function to get list of files in your music directory
like this $musics = list('/musicdir/'); //this will return as an array.
return $musics(rand(0,count($musics));
note: the bracket after $musics should not be so i only used a normal bracket because i am typing with my phone.

if ($a != 'new')
use list function to get list of files in your music directory
like this $musics = list('/musicdir/'); //this will return as an array.
-Then use php pop function to remove the music that has been played from the array, ie, $musics = pop($a,$music) So that an the music that just finished playing will not repeat itself
-return $musics(rand(0,count($musics));

Here is how mediaReturner.php:
include 'mediaController.php';
$song = mediaControl($_GET(cursor));
if(!empty($song))
header('Content-Type:audio/mp3')
echo $song;
else
header('Location://No music available page).

That is all i can contribute cause , i just started writin this algorithm immediately i saw ur thread.. I culd have written the actual codes but i can insert some syntax with my mobile phone..

If do not knw hw to programme i sugest u show dis to a programmer he/she will understand and help u better..
Note: the algorithm may have some flaws, but u can add urs to it , what i gave is jst the basics.. Thank You.

1 Like

Re: Want To Create A Music Playlist Using PHP, Ideas Pls by cbrass(m): 11:05pm On Jun 21, 2016
Teamprega, I really appreciate your input but it still a bit confusing to me, codehouse method seems to be inline with what am thinking but still needs more clarification. If the users won't be using a desktop or tablet they will see a link they can click to listen
Re: Want To Create A Music Playlist Using PHP, Ideas Pls by teampregar(m): 11:17am On Jun 22, 2016
cbrass:
Teamprega, I really appreciate your input but it still a bit confusing to me, codehouse method seems to be inline with what am thinking but still needs more clarification. If the users won't be using a desktop or tablet they will see a link they can click to listen
K, i advise what i posted to a php developer and someone who understands algorithm implementation , i would have written the entire codes of how it will work and give to u bt i am busy dats y i just gave an algorithm.
In general here i how my solution works:
STACK : PHP, JAVASCRIPT, HTML, DOM..
1. A visitor visits ur website(radio station that plays music)
2.Visitor clicks turn on radio button.
3.Onclick of turn on radio button javascript uses ajax to get any song on your server.
4.If a song was found it plays song, Else it goes to no song available error page.
5.Before javascript plays the song it sets an onafterplay HTML event attribute .
6. When onafterplay event occurs the process in number 3 is triggered again. So different songs continue to play until the Visitor presses the turn off radio station button..
Re: Want To Create A Music Playlist Using PHP, Ideas Pls by cbrass(m): 12:28pm On Jun 22, 2016
teampregar:
K, i advise what i posted to a php developer and someone who understands algorithm implementation , i would have written the entire codes of how it will work and give to u bt i am busy dats y i just gave an algorithm.
In general here i how my solution works:
STACK : PHP, JAVASCRIPT, HTML, DOM..
1. A visitor visits ur website(radio station that plays music)
2.Visitor clicks turn on radio button.
3.Onclick of turn on radio button javascript uses ajax to get any song on your server.
4.If a song was found it plays song, Else it goes to no song available error page.
5.Before javascript plays the song it sets an onafterplay HTML event attribute .
6. When onafterplay event occurs the process in number 3 is triggered again. So different songs continue to play until the Visitor presses the turn off radio station button..

Better this way, thanks a lot grin

(1) (Reply)

Will There Still Be A Need For Programmers In The Future? / Java Resource CD For Nairaland / How To Build Geo-tracking Apps With AngularJS, Ionic & The Salesforce REST API

(Go Up)

Sections: politics (1) business autos (1) jobs (1) career education (1) romance computers phones travel sports fashion health
religion celebs tv-movies music-radio literature webmasters programming techmarket

Links: (1) (2) (3) (4) (5) (6) (7) (8) (9) (10)

Nairaland - Copyright © 2005 - 2024 Oluwaseun Osewa. All rights reserved. See How To Advertise. 24
Disclaimer: Every Nairaland member is solely responsible for anything that he/she posts or uploads on Nairaland.