Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.

[RESOLVED] Bug with Audio Source uploading an AudioClip from a video?

Discussion in 'Windows' started by nino4, Sep 12, 2014.

  1. nino4

    nino4

    Joined:
    Sep 9, 2014
    Posts:
    2
    Hi all.

    I googled all the web and I hope to find a solution here for my problem. I am testing Unity 4.3.4 for a project but now I am in front of a wall. The projet is simple:
    .a place
    .Televisions that play videos witch can be controled by script (play, pose, stop) by selected players, with a linear rolloff on distance from 0.1 to 6 unities to hear the video sound only if we are near the television.

    It is easy if we import the video in Unity, assign a MovieTexture in a script, put this script in a gameobject with an Audio Sound and set up the 3D sound settings and the movie audioclip.

    But, I would like to allow selected players to change the videos on televisions by uploading them from a folder on the server (the videos are all made by companies and not copyrighted films)
    This upload code is done, here it is the video upload:

    private IEnumerator LoadVideo(string fullFilename)
    {
    string fullfile = "file:///"+fullFilename.Replace("\\","/");

    WWW www = new WWW(fullfile);
    yield return www;

    LaVideo = www.movie; // LaVideo is a Movietexture

    gameObject.renderer.material.mainTexture = LaVideo as MovieTexture; // = LaVideo as MovieTexture or = LaVideo does not change anything
    LaVideo.loop = true;

    audio.clip = LaVideo.audioClip;

    audio.minDistance = 0.1f;
    audio.maxDistance = 6.0f;
    audio.panLevel = 1.0f;
    audio.pan = 0.1f;
    audio.spread = 0.0f;
    audio.volume = 1.0f;
    audio.rolloffMode = AudioRolloffMode.Linear;

    LaVideo.Play();
    audio.Play();

    playingVideo = true;
    }


    My problem is, if I change and load by script in the Audio Source un AudioClip witch is a part of a video , even if I script the 3d sound settings of he Audio Sound, I can see the 3d sound setting in the inspector changing but they are not applyed on the server, on the player with classic function call or RPc call. The only way I have to apply them is to manage the values in the inspector with mouse and then all is ok for MY player but not allbuffered. My problem is "maxdistance" hearing.
    I did read in some posts that it is a Unity bug. Some people found the solution by the following code (it is a labyrinthine system)

    void Update()
    {
    if(playingVideo == true) // playingVideo dans le code ci-dessus
    {
    audio.minDistance = 0.1f;
    audio.maxDistance = 6.0f;
    audio.panLevel = 1.0f;
    audio.pan = 0.1f;
    audio.spread = 0.0f;
    audio.volume = 1.0f;
    audio.rolloffMode = AudioRolloffMode.Linear;
    }
    }

    and for me it does not work.
    Some people says that it will work if you take the video, remove the audio and play it. Yes it works, but if you did read me before, companies will upload there videos....... That will be hard for them just for a video to use VLC. They don't have a geek in place to remove the sound.

    Any idees? because from 2012, a lot of people send this report but it seems that Unity did not found a solution. Hope to read you all
     
    Last edited: Sep 16, 2014
  2. nino4

    nino4

    Joined:
    Sep 9, 2014
    Posts:
    2
    Sorry If I took time to send the solution. This is the code

    private IEnumerator LoadVideo(string fullFilename)
    {
    string fullfile = "file:///"+fullFilename.Replace("\\","/");

    WWW www = new WWW(fullfile);
    while( !www.isDone )
    yield return null;

    www.GetAudioClip(true,true);
    LaVideo = www.movie;

    gameObject.renderer.material.color = new Color(1, 1, 1, 0);
    gameObject.renderer.material.mainTexture = LaVideo as MovieTexture;

    audio.minDistance = 0.1f;
    audio.maxDistance = 6.0f;
    audio.panLevel = 1.0f;
    audio.pan = 0.1f;
    audio.spread = 0.0f;
    audio.volume = 1.0f;
    audio.rolloffMode = AudioRolloffMode.Linear;

    audio.clip = www.GetAudioClip(true,true,AudioType.OGGVORBIS);

    while (!this.audio.clip.isReadyToPlay )
    {
    Debug.Log("audio stream not ready");
    yield return null;
    }
    LaVideo.Play();
    audio.Play();
    playingVideo = true;
    }


    by adding to this code
    LaVideo.loop = true;
    audio.loop = true;


    only the video was looping but the audio was playing once (I don't know why). So I removed these 2 lines of code and find the way to loop like that:

    void Update ()
    {
    if(playingVideo == true)
    {
    if(!LaVideo.isPlaying && !audio.isPlaying)
    {
    playingVideo = false;
    LaVideo.Stop();
    // you have to stop before playing again
    audio.Stop(); // you have to stop before playing again

    LaVideo.Play();
    audio.Play();
    StartCoroutine(WaitStartingFilm());
    // to avoid the sytem looping in starting the video and sound
    }
    }
    }

    IEnumerator WaitStartingFilm()
    {
    yield return new WaitForSeconds (1.0f);
    playingVideo = true;
    }


    Hope that will help some of you and thanks to those who searched with me.