Page 1 sur 1

Probleme de son avec le video player?

Publié : 13 Mai 2018 01:18
par grex
bonjour,
J'ai suivi ce tutorial qui explique comment utiliser le video player sans code:
https://www.youtube.com/watch?v=fT5fMP_F1o0
Sur le site upln il montre un code d'exemple pour charger la video depuis le script:
https://upln.fr/cinematique-lire-une-vi ... vec-unity/

Le problème c'est que avec ce code l'audiosource qui est rattaché au video player ne se lance pas quand la vidéo se lance.

Code : Tout sélectionner

using UnityEngine;
 
public class HTTPVideoScript : MonoBehaviour {
    
    // Use this for initialization
    void Start () {
        var vPlayer = gameObject.AddComponent<UnityEngine.Video.VideoPlayer>();
        vPlayer.URL = "http://www.quirksmode.org/html5/videos/big_buck_bunny.mp4";
        vPlayer.target = UnityEngine.Video.VideoTarget.CameraFrontPlane;
        vPlayer.alpha = 0.5f;
        vPlayer.prepareCompleted += Prepared;
        vPlayer.Prepare();
    }
    
    void Prepared(UnityEngine.Video.VideoPlayer vPlayer) {
        Debug.Log("End reached!");
        vPlayer.Play();
    }
}

Re: Probleme de son avec le video player?

Publié : 13 Mai 2018 14:19
par Max
Hello,

les liens video que tu donnes (UPN) montrent une configuration faite entièrement à partir de l'inspector.
Dans ton cas, visiblement, tu cherches à créer les composants en runtime et tu pars sur une lecture en URL.
Concernant l'audiosource, il est spécifié dans la doc ceci:
The audio source’s playback controls (Play On Awake and Play() in scripting API) do not apply to the video source’s audio track.

Si je reprends ton code, en le complétant, cela pourrait donner ceci (Unity 2017.3):
Ajout des components VideoPlayer et AudioSource

Code : Tout sélectionner

    // Use this for initialization
    void Start()
    {
        VideoPlayer vPlayer = gameObject.AddComponent<VideoPlayer>();
        AudioSource audio = gameObject.AddComponent<AudioSource>();
        // IMPORTANT, cf la doc
        vPlayer.playOnAwake = false;
        audio.playOnAwake = false;

        vPlayer.url = "http://www.quirksmode.org/html5/videos/big_buck_bunny.mp4";
        vPlayer.renderMode = VideoRenderMode.CameraNearPlane;
        vPlayer.targetCamera = Camera.main;
       
        vPlayer.audioOutputMode = VideoAudioOutputMode.AudioSource;        
        vPlayer.controlledAudioTrackCount = 1;
        vPlayer.EnableAudioTrack(0, true);
        vPlayer.SetTargetAudioSource(0, audio);

        vPlayer.prepareCompleted += Prepared;
        vPlayer.Prepare();     
    }
    
    void Prepared(VideoPlayer vPlayer)
    {
        Debug.Log("End reached!");
        vPlayer.Play();
    }