Search Unity

Video VideoPlayer 2017.3 does not play audio

Discussion in 'Audio & Video' started by roumenf, Oct 16, 2017.

  1. roumenf

    roumenf

    Joined:
    Dec 12, 2012
    Posts:
    635
    Hi,

    I have VideoPlayer configured to play mp4-video from local file URL. The audio output is AudioSource. This worked already on Unity 5.6 & 2017.1. After the upgrade to Unity 2017.3 (I tried b4 & b3 beta-versions, as well as 2017.2.0f3), the video plays OK, but the audio is not playing at all. After reading the VideoPlayer script reference, I added this line after Prepare():
    "
    videoPlayer.controlledAudioTrackCount = videoPlayer.audioTrackCount;
    "
    But the audio is still not playing. If I set the same video to play from VideoClip instead of URL, the audio is playing. What am I missing?
     
    Last edited: Oct 16, 2017
  2. roumenf

    roumenf

    Joined:
    Dec 12, 2012
    Posts:
    635
    I think I found a workaround:
    "
    videoPlayer.controlledAudioTrackCount = 1;
    "
     
  3. Tryz

    Tryz

    Joined:
    Apr 22, 2013
    Posts:
    3,402
    I had to set the "source" first. Then, setting the controlledAudioTrackCount = 1 worked for me.

    Code (CSharp):
    1. VideoPlayer lPlayer = gameObject.GetComponent<VideoPlayer>();
    2. lPlayer.source = UnityEngine.Video.VideoSource.Url;
    3. lPlayer.audioOutputMode = UnityEngine.Video.VideoAudioOutputMode.AudioSource;
    4. lPlayer.controlledAudioTrackCount = 1;
    5. lPlayer.EnableAudioTrack(0, true);
    6. lPlayer.SetTargetAudioSource(0, lAudioSource);
    Do this before loading and playing.
     
    roumenf likes this.
  4. roumenf

    roumenf

    Joined:
    Dec 12, 2012
    Posts:
    635
    The issue was that before 2017.3.0 the controlledAudioTrackCount-property was set to 1 internally. Now it's 0, and the developer should set it explicitly, if the source is URL. If the source is VideoClip, it's set automatically from the clip's meta-data.