Board index   FAQ   Search  
Register  Login
Board index php forum :: php coding PHP coding => General

Music Stream echo wrong links to mp3 files

Ask about general coding issues or problems here.

Moderators: macek, egami, gesf

Music Stream echo wrong links to mp3 files

Postby Fijiannn » Wed Jan 08, 2014 9:31 pm

Below I have this PHP script and a folder called "songs" on my host. What my script does is it access the mp3 music in my songs folder and shuffles them. Then creates an array of links to each song that outputs through $body. The problem I seem to be having is when I test this script on my iPhone app, it outputs all the links in the songs folder in my console and the music begins to stream. The first link I would think would be the first song that is streaming but it's not. What is wrong with my code? Below is my my PHP script.

Code: Select all
<?php

    function myFunction($url) {
        $a = join('/', array_map('urlencode', explode('/', $url)));
        return str_replace('+', '%20', $a);
    }

    $SongsFolder = "songs";

    header("Content-Type: audio/x-mpegurl");

    $body = '';

    $Songs = glob($SongsFolder."/*.mp3");
    shuffle($Songs);
    $first = 0;

    foreach($Songs as $Song)
    {
        $SongPath = pathinfo($Song);
        if ($first != 0) {
            $body .= "\n";
        }
        $first = 1;
        $body .= "http://".$_SERVER['HTTP_HOST'].myFunction(dirname($_SERVER['PHP_SELF']))."/".myFunction($SongsFolder)."/".myFunction($SongPath['basename']);
    }
    header('Content-Length: ' . strlen($body));
    echo $body;
?>


Here is what my console outputs.

Code: Select all
2014-01-08 21:03:50.411 Virsa[2865:54d2f] http://virsamusic.com/VirsaApp/Punjabi/Old%20School/songs/06%20Aa-Sohnien.mp3
http://virsamusic.com/VirsaApp/Punjabi/Old%20School/songs/11%20JAN%20AAYI%20KHER.mp3
http://virsamusic.com/VirsaApp/Punjabi/Old%20School/songs/07%20SANOO%20NACH%20KE.mp3
http://virsamusic.com/VirsaApp/Punjabi/Old%20School/songs/02%20Veera%20Ve%20Sun%20Ammrhi%20Jayeaa.mp3
http://virsamusic.com/VirsaApp/Punjabi/Old%20School/songs/01%20Likhda%20Reha%20Main.mp3
http://virsamusic.com/VirsaApp/Punjabi/Old%20School/songs/1-01%20Kali%20Teri%20Gut.mp3
http://virsamusic.com/VirsaApp/Punjabi/Old%20School/songs/11%20Bebe%20Joga.mp3
http://virsamusic.com/VirsaApp/Punjabi/Old%20School/songs/Umar%20Gawa%20Lai%20Tu.mp3
http://virsamusic.com/VirsaApp/Punjabi/Old%20School/songs/03%20PARTAPI%20SUNYARI.mp3
Fijiannn
New php-forum User
New php-forum User
 
Posts: 1
Joined: Wed Jan 08, 2014 9:29 pm

Return to PHP coding => General

Who is online

Users browsing this forum: No registered users and 1 guest

Sponsored by Sitebuilder Web hosting and Traduzioni Italiano Rumeno and antispam for cPanel.