- Home /
Download Audioclip from youtube URL with WWW
Hello, im currently trying to make a script where players can select their own music.
I made a script that works with .ogg links, but i cant seem to make youtube links works since unity does not recognize the audio source in the link.
Code:
@script RequireComponent (AudioSource)
var url = "https://www.youtube.com/watch?v=Og83qIIQsmw";
var native_width : float = 1920;
var native_height : float = 1080;
function OnMouseDown () {
var www : WWW = new WWW (url); // start a download of the given URL
audio.clip = www.GetAudioClip(false, true); // 2D, streaming
}
function Update() {
if (!audio.isPlaying && audio.clip.isReadyToPlay)
{
audio.Play();
}
else
{
Debug.Log("waiting - isplaying : " + audio.isPlaying + " isreadyToPlay : " + audio.clip.isReadyToPlay);
}
}
function OnGUI () {
var rx : float = Screen.width / native_width;
var ry : float = Screen.height / native_height;
GUI.matrix = Matrix4x4.TRS (Vector3(0, 0, 0), Quaternion.identity, Vector3 (rx, ry, 1));
url = GUI.TextField (Rect (1300, 700, 300, 70), url, 100);
}
Error Code:
Unable to determine the audio type from the URL (https://www.youtube.com/watch?v=Og83qIIQsmw) . Please specify the type. UnityEngine.WWW:GetAudioClip(Boolean, Boolean)
Im pretty sure i just can't download the Audiofile from a youtube link it self, but i need a direct link to the video instead. Does anyone know how to do that? Without making the players having to lots of stuff themselves, such as downloading then converting etc?
Im very new to WWW and usually just mess around with GUI and Physics. If there is any more information you need dont hesitate asking me.
Thanks in advance ^^
WWW
can't download random YouTube vids and play them back. WWW
can fetch audio clips, but they need to be in a format that Unity understands, which, as the docs say, means Ogg or Wav. $$anonymous$$ovies must be in Ogg Theora format.
I think i understood it so far, but is it a way to make the youtube link a direct link like common .ogg links. I just think it would be a hassle if players had to download the youtube video for themself, then convert it to ogg, then upload it to a webserver, then be able to use their link in-game. If there is no real way then i guess it'll just have to do. But i am pretty sure mp3 files are capable for playback, or maybe that is only on IOS.
Answer by unity_GcNq3AitVEePDA · Jun 04, 2018 at 01:21 PM
I am Use Mp3xd online youtube converter website for using Download Any video on youtube. because it's fast, secure and easy to use.
Answer by josephmiller · Jun 04, 2018 at 05:14 AM
All those who are fond of music must have heard about mp3converter.live because a number of users rely on this astonishing downloader to save their favorite media file. Follow this Step:-
1. Just paste your favorite youtube video URL. 2. Select Format. 3. Click the download button.
No, It's not illegal. It's Fully legal.
I see. I still wouldn't risk it, just to be sure.
Your answer
Follow this Question
Related Questions
How to stream audio from a URL? 0 Answers
Stream audio from a YouTube playlist's URL? 0 Answers
WWW Audio and PlayOneShot: Playing the same AudioClip Twice Cuts off First Instance 1 Answer
How to get this .mp3 conversion script to play through an audio source? 0 Answers
Loading ogg though WWW results in 3D Sound, need as 2D... 3 Answers