Welcome!

By registering with us, you'll be able to discuss, share and private message with other members of our community.

SignUp Now!
  • Guest, before posting your code please take these rules into consideration:
    • It is required to use our BBCode feature to display your code. While within the editor click < / > or >_ and place your code within the BB Code prompt. This helps others with finding a solution by making it easier to read and easier to copy.
    • You can also use markdown to share your code. When using markdown your code will be automatically converted to BBCode. For help with markdown check out the markdown guide.
    • Don't share a wall of code. All we want is the problem area, the code related to your issue.


    To learn more about how to use our BBCode feature, please click here.

    Thank you, Code Forum.

HTML html audio control cant find .mp3 in folder

Wes.

Active Coder
Hello. I have an html audio control on my site. The .mp3 files it takes as it's source are in a folder called Samples. This has always worked fine in my old Classic ASP site, but I am now re-writing the site in PHP and I have found that the audio control will only work if my .mp3 files are in the root directory. I have a lot of them and I dont really want them scattered all over the root directory, it's much neater to have them all together in a folder. How can I get this to work? or if it wont, is there another solution? Many thanks for any help.
 
Hello. I have an html audio control on my site. The .mp3 files it takes as it's source are in a folder called Samples. This has always worked fine in my old Classic ASP site, but I am now re-writing the site in PHP and I have found that the audio control will only work if my .mp3 files are in the root directory. I have a lot of them and I dont really want them scattered all over the root directory, it's much neater to have them all together in a folder. How can I get this to work? or if it wont, is there another solution? Many thanks for any help.
Hey and welcome :D

most likely you have a directory issue within the code but i really need to see your code before i can help :), if you could upload your code using BB Code then i would be happy to take alook :D
 
Hi, thanks for your reply. The .mp3 files are in a folder called "Samples". The page which displays the Audio Control is in the root directory. It displays a list of pieces of music and the invitation to listen to each one.
$row["Listen"] contains "/Samples/some_audio_file_name.mp3" according to which of the audio files apply to the particular item in the list.
The code works fine if I copy an audio file to the root directory and change $SamplesPath accordingly, but otherwise it displays in a 'greyed out' state and refuses to work.

The code which calls the Audio Control is as follows:-

PHP:
                    $SamplesPath = ("www.fmtest.info" .  $row["Listen"]);            //define the path to the samples folder

                        echo "<tr>";

                            echo "<td Style='line-height: 45px; border: 0px solid black;'  colspan='2' >";

                                echo "<img src='images/Listen.jpg' WIDTH='35' HEIGHT='50' ALT='Listen' TITLE='Listen' ALIGN='left' >";

                                echo "&nbsp;&nbsp;Listen to this music";

                            echo "</td>";

                            echo "<td Style='line-height: 5px; text-align: left; border: 0px solid black;' colspan='2'>";

                            ?>

                                <audio controls style="width: 500px; z-index:0;">

                                    <source src=" . $SamplesPath . " type='audio/mpeg'>

                                </audio>

                            <?php

                            echo "</td>";

                        echo "</tr>";

Many thanks for any help you can give me.
 
Last edited by a moderator:
i cant really help too much as everything is in a database unless you can send it all over, so this may take a while :D

looking at your code,
HTML:
<audio controls style="width: 500px; z-index:0;">
<source src=" . $SamplesPath . " type='audio/mpeg'>
</audio>

is outside of a php tag so you need to do
HTML:
<audio controls style="width: 500px; z-index:0;">
<source src="<?PHP echo $SamplesPath; ?>" type='audio/mpeg'>
</audio>

that should now work
 
Ah yes I see what I've done there, used a php variable in a line of html ☹️ however I'm sorry but it still doesn't work. Could you clarify a couple of things?
1. I've got an alert telling me I should have put the code in the Code Editor. How do I do that?
and
2. What do you mean by "i cant really help too much as everything is in a database"

Cheers.
 
Click that icon and then put your code in there :D

Usually, i would say send me over your code and ill have a look, the issue is where your calling from a database I cannot see what's happening.

Add this code and paste the output here :)

Code:
 echo $SamplesPath;
 echo $row["Listen"];
 
PHP:
echo $SamplesPath; = "www.fmtest.info"
echo $row["Listen"]; = "/Samples/AmericanPie.mp3"  so when concatenated they make the path
"www.fmtest.info/Samples/AmericanPie.mp3"
 
Great to hear you solved it :D i thought it would be something simple thats why i was getting you to echo the outputs as i checked your code and it was fine :D

If you need any more help, just reach out :D
 
Back
Top Bottom