I solved this crap myself. Unity needs better documentation on USAGE not specification, specification is great.

@OP
comment the line for audioSource.Play(). If you trigger video and audio it fails to play audio.
The problem is that we are all referencing source code from examples that are dated and no longer 100% valid.

The only other difference to your code from mine, where mine is working, and outside the mentioned change, is:
audioSource.volume=1.0f;
audioSource.controlledAudioTrackCount=1;
prior to the Prepare() statement (actually you don't have that either).

Use the callbacks...
vPlayer.loopPointReached and vPlayer.prepareCompleted.

I'm currently having the same problem. Video plays find in texture however no sound at all. Where can I access the video player embedded script to add the values you guys listed? I can't find access to it (script) in inspector.

Just in case anyone is looking for working code. Here is what I have so far:

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.Video;
public class PlayVideo1 : MonoBehaviour
{
public VideoPlayer videoPlayer;
public AudioSource audioPlayer;
void OnEnable()
{
// Will attach a VideoPlayer to the main camera.
GameObject camera = GameObject.Find("Camera");
// VideoPlayer automatically targets the camera backplane when it is added
// to a camera object, no need to change videoPlayer.targetCamera.
videoPlayer = camera.AddComponent<VideoPlayer>();
audioPlayer = gameObject.AddComponent<AudioSource>();
// Play on awake defaults to true. Set it to false to avoid the url set
// below to auto-start playback since we're in Start(). // Changed to "onEnable"
videoPlayer.playOnAwake = false;
audioPlayer.playOnAwake = false;
// By default, VideoPlayers added to a camera will use the far plane.
// Let's target the near plane instead.
videoPlayer.renderMode = VideoRenderMode.CameraNearPlane;
// This will cause our scene to be visible through the video being played. // Changed it to 1.0 for it not to be transparent
videoPlayer.targetCameraAlpha = 1.0F;
// Restart from beginning when done. // Do not restart when done playing
videoPlayer.isLooping = false;
// Set the video to play. URL supports local absolute or relative paths.
// Here, using absolute.
videoPlayer.url = "C:/Users/user/Documents/vid.mp4";
videoPlayer.audioOutputMode = VideoAudioOutputMode.AudioSource;
videoPlayer.EnableAudioTrack(0, true);
videoPlayer.SetTargetAudioSource(0, audioPlayer);
videoPlayer.controlledAudioTrackCount = 1;
audioPlayer.volume = 1.0f;
//audioPlayer.controlledAudioTrackCount = 1;
}
public void PlayVid ()
{

Audio settings seem to work differently when playing from a clip and from a URL. For playing from a URL, in 2018.1.2f1, the correct sequence to set up the player is this. First, set up the player; player must be stopped for this, and not been Prepare()d yet.

Audio settings seem to work differently when playing from a clip and from a URL. For playing from a URL, in 2018.1.2f1, the correct sequence to set up the player is this. First, set up the player; player must be stopped for this, and not been Prepare()d yet.

Does anyone have any tips of getting a video to play with audio via a URL (in StreamingAssets) in 2017.4.4? I've been trying all day to get this to work. Here's where I'm at:

- If I use a VideoClip version of my movie, it works fine
- If I manually add the VideoPlayer and AudioSource components to my GameObject and use the same settings as in my script, it works fine
- But, if I create the VideoPlayer and AudioSource via code, the video plays fine, but no audio plays.

This leads me to believe it might be some kind of timing/initialization thing? But I'm running out of ideas. This is what my code looks like:

I have tried it with playOnAwake set to true for both the audio and video. I've tried it without the coroutine and using playOnAwake set to true. I've tried just playing the video without prepping it. But if I run the game with this code and copy the components and paste them back onto my gameobject in the scene, it works with these exact settings.

I'm kind of at a loss about what to try next. For various reasons it's unfortunately not an option to leave the VideoPlayer component active on the GameObject at all times. Anyone got any ideas? Is this a known issue in 2017.4.4? Or am I doing something dumb?

For anyone coming along later, I found a solution that's good enough for me. Instead of creating things via code, I created the VideoPlayer and AudioSource on a GameObject in my scene, then saved that out as a prefab to my Resources folder, then deleted it from the scene. Now I can load and instantiate the prefab at runtime, set the URL on the VideoPlayer component, and it all works. I have no idea why the code-only way doesn't work. Maybe it's a problem in 2017.4.4, or something I was doing wrong, but at least I have working audio and video now.

I'm having trouble with this too. Everything works fine in the editor, but when deployed to an Android S8 the video plays without sound. I'm on Unity 2018.2.12f1, and for testing I created a new project that only has one empty object added with the following script:

Code (CSharp):

publicclass VideoTest : MonoBehaviour {

public VideoPlayer videoPlayer;

public AudioSource audioPlayer;

void OnEnable()

{

// Will attach a VideoPlayer to the main camera.

GameObject camera = GameObject.Find("Main Camera");

// VideoPlayer automatically targets the camera backplane when it is added

// to a camera object, no need to change videoPlayer.targetCamera.

videoPlayer = camera.AddComponent<VideoPlayer>();

audioPlayer = gameObject.AddComponent<AudioSource>();

// Play on awake defaults to true. Set it to false to avoid the url set

// below to auto-start playback since we're in Start(). // Changed to "onEnable"

videoPlayer.playOnAwake=false;

audioPlayer.playOnAwake=false;

// By default, VideoPlayers added to a camera will use the far plane.

// Let's target the near plane instead.

videoPlayer.renderMode= VideoRenderMode.CameraNearPlane;

// This will cause our scene to be visible through the video being played. // Changed it to 1.0 for it not to be transparent

videoPlayer.targetCameraAlpha= 1.0F;

// Restart from beginning when done. // Do not restart when done playing

videoPlayer.isLooping=false;

// Set the video to play. URL supports local absolute or relative paths.

I'm having trouble with this too. Everything works fine in the editor, but when deployed to an Android S8 the video plays without sound. I'm on Unity 2018.2.12f1, and for testing I created a new project that only has one empty object added with the following script:

Code (CSharp):

publicclass VideoTest : MonoBehaviour {

public VideoPlayer videoPlayer;

public AudioSource audioPlayer;

void OnEnable()

{

// Will attach a VideoPlayer to the main camera.

GameObject camera = GameObject.Find("Main Camera");

// VideoPlayer automatically targets the camera backplane when it is added

// to a camera object, no need to change videoPlayer.targetCamera.

videoPlayer = camera.AddComponent<VideoPlayer>();

audioPlayer = gameObject.AddComponent<AudioSource>();

// Play on awake defaults to true. Set it to false to avoid the url set

// below to auto-start playback since we're in Start(). // Changed to "onEnable"

videoPlayer.playOnAwake=false;

audioPlayer.playOnAwake=false;

// By default, VideoPlayers added to a camera will use the far plane.

// Let's target the near plane instead.

videoPlayer.renderMode= VideoRenderMode.CameraNearPlane;

// This will cause our scene to be visible through the video being played. // Changed it to 1.0 for it not to be transparent

videoPlayer.targetCameraAlpha= 1.0F;

// Restart from beginning when done. // Do not restart when done playing

videoPlayer.isLooping=false;

// Set the video to play. URL supports local absolute or relative paths.

I exported an app and the video plays, but no sound was coming out on Android phone.
I found this video,

and thought the guys was crazy, but I tried it anyway, sure enough, the sound was playing in the headphone, and by messing with the volume, with and without the headphone, it actually fixed the sound problem!!! go figure

Oops...

"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.