We're a community of 1077K IT Pros here for help, advice, solutions, professional growth and fun. Join us!
1,076,496 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Start New Discussion Reply to this Discussion
Page 2 of Article: Help with redirect type thing
I'm thinking of hosting a *name that tune* type game. I don't know anything about PHP or even if it's the languge to use, but I'm hoping someone might put me straight on that matter too. Here is an outline of my needs/scenario. I post a link to a song.mp3…

The html works fine, shows a little player, and plays just great.

<!DOCTYPE html>
<html>
<body>

<audio controls>
  <source src="NewMp3.mp3" type="audio/mpeg">
  <embed height="50" width="100" src="NewMp3.mp3">
</audio>

</body>
</html>
Suzie999
Posting Whiz
321 posts since Jul 2010
Reputation Points: 49
Solved Threads: 15
Skill Endorsements: 0

Sorry, I have to remove it my response. I think you already got it sorted out..

veedeoo
Master Poster
735 posts since Oct 2011
Reputation Points: 298
Solved Threads: 130
Skill Endorsements: 13

I have not got it sorted, maybe I gave the wrong impression (it's how my first was born).
This just puts a player in a page on my site and clearly shows the song name, which is the whole point of my problem.

Suzie999
Posting Whiz
321 posts since Jul 2010
Reputation Points: 49
Solved Threads: 15
Skill Endorsements: 0

ok, here we go again. I am not going to provide any link because, for some reason the mp3 I would like to be the demo for this response is misbehaving badly :).

I only tested this on IE, because that is the only one I have at the moment.

Here we go, we can provide link from any page using this syntax

    <a href="mp3streamer.php?file=pinkfloyd">Pink Floyd </a>

Ok, just to remind you that the file name is up to you. YOu can rename your mp3 like mysterysong101.mp3, it does not matter.

Here is the script..

    <?php
    ## Warning! not tested in firefox ONLY in IE. This script triggers the windows media player.

    if(isset($_GET['file']) && (!empty($_GET['file']))){
     $thisMp3 = mp3Streamer($_GET['file'],'.mp3');
    }
    else{

    //nothing 

    }

    function mp3Streamer($title,$ext){

    ## define secret directory
    $loc = 'uploads/';

    ## based on the known vars we have the actual filename, location, and extension
    $actual_file = $loc.$title.$ext;
    ## mime types possible
    $mType = "  audio/mpeg3, audio/x-mpeg, audio/x-mpeg-3, audio/mpeg"; 
    ## we double check and make file exist
    if(file_exists($actual_file)){

    ## do as what we already know
        header('Content-type: {$mType}');
        header('Content-length: ' . filesize($actual_file));
        header('Content-Disposition: filename="'. $actual_file .'"');
        header('X-Pad: avoid browser bug');
        header('Cache-Control: no-cache');
        $mfile = readfile($actual_file);

        ## ! source src was left blank intentionally ##
        ###############################################

        $thisAudio = '<audio controls height="100" width="100">
      <source src="" type="audio/mpeg">
      <embed height="50" width="100" src="'.$mfile.'">
       </audio> ';
    die(); 
    }

    else{

    $thisAudio = 'not available';

    }

    return $thisAudio;

    }

    ?>

Good luck to you.. :)

veedeoo
Master Poster
735 posts since Oct 2011
Reputation Points: 298
Solved Threads: 130
Skill Endorsements: 13

Hi veedeoo, thank you for your time and effort.
Your script works fine as it is supposed to, but unfortunately is the same as
the codes above, in that if I view the page source, the title and artist are clearly visible, and it does not work in media tags either in chrome, IE or firefox.

When I started this thread, It was my hope that I could have a link "www.domain.com/fakemp3.mp3" but when navigated to of put in tags, a different song would be served.

Thank you all once again for trying, but I believe it not possible at this time and try to think of another method of acheiving my goal.

Cheers.

Suzie999
Posting Whiz
321 posts since Jul 2010
Reputation Points: 49
Solved Threads: 15
Skill Endorsements: 0

This article has been dead for over three months: Start a new discussion instead

Post: Markdown Syntax: Formatting Help
 
You
 
 
© 2013 DaniWeb® LLC
Page rendered in 0.0671 seconds using 2.68MB