Stream audio files from my home computer to my website

好久不见. 提交于 2019-12-12 03:39:29

问题


Hello! I have a couple of questions regarding a website I have been building that requires audio files to be echoed onto my HTML using PHP after referencing my SQL database.

To begin, my page has an audio control tag that has a php echo inside of it, like so:

<audio controls>
    <source src="audio/<?php echo $file; ?>" type="audio/mp3">
</audio controls>

the variable $file is equal to the audio file the user wants to play after they fill out a select form on a different page, which is pulled from my database:

INSERT INTO table
    VALUES
    (NULL, "track01.mp3");
    (NULL, "track02.mp3");
    (NULL, "track03.mp3");
    (NULL, "track04.mp3");

so therefore, if the user picks the first track from the select form, the HTML looks like this:

<audio controls>
    <source src="audio/track01.mp3" type="audio/mp3">
</audio controls>

EVERYTHING WORKS UP TO THIS POINT

My audio is loading perfectly fine and the php/mysql code is working great; the problem that I am having is that I am going to have over 5 gigabytes of audio in my database, which I cannot put onto my web server due to disk space limits. So I thought, "how can I get my audio to stream to my website, so I don't have to have 5 gigabytes on my website?"

So I began to research utilizing an Apache server (since I was already using WAMP to test my site out) and try to get that server to link to my website.

My first test was placing all of my music onto my localhost and then I changed the code on my live website to call the files like this:

<audio controls>
    <source src="http://localhost/audio/<?php echo $file; ?>" type="audio/mp3">
</audio controls>

This also works perfectly fine, but obviously this will not work for anyone else since they do not have access to my localhost on their own computer.

So my big question is, how can I set my website up so my php will echo out a file from the localhost on my home computer, but also allow anyone who views my site to be able to see the audio tag with no errors? I assume this would have something to do with everyone having access to my IP address but everything I have tried so far has failed. Is there a solution to my problem? Am I taking the wrong approach to this? Is there anything I should specify?

Any answer would be greatly appreciated. Thank you!


回答1:


I would look to cloud storage - there are many engines that give very good prices / some free. For example Amazon S3, Box, DropBox etc. I have over 50Gb free storage at the moment and many of these providers offer http access to shared directories - as long as you are not breaking any copyright laws etc.




回答2:


First of all its not recommended to host files from home computer

  • You can't keep your computer on 24/7

  • You can't have over 99% uptime from your ISP

  • You won't get 100mbps or 1gig/s port at home so that users can listen your audio seamlessly

If you still want to continue with this, you need static IP or Domain pointed to your PC, Port 80 (Apache) must be open. Your files in database will point to http://(your-ip / domain-of-your-pc)/filepath where filepath is folder inside your xampp / wamp.

Static IP : WAN IP from your internet provider which won't change on reconnection everytime.

Tip :

  • you can use NO-IP if you don't have static ip or seprate domain to your PC.
  • You can still point 1 subdomain to your PC ip like data.yourdomain.com which will look some professional :)



回答3:


This requires several steps and decent upload bandwidth.

  1. Configure your router to accept port 80 requests and forward it to your PC
  2. In your live website you would need to reference audio files using your public IP like this <source src="http://24.35.158.64/audio/track01.mp3" type="audio/mp3">
  3. Configure apache to listen for that IP address and route it to your MP3 folder

Depending on your ISP this will either be possible or impossible.



来源:https://stackoverflow.com/questions/21837871/stream-audio-files-from-my-home-computer-to-my-website

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!