- Home /
Question by
jonAtNvizzio · Oct 11, 2018 at 03:25 PM ·
audiovideostreamingassets
VideoPlayer: No audio when playing from StreamingAssets
When playing a video by url with the VideoPlayer component I get no audio. The url is of an asset in the StreaamingAssets folder and is of the mp4 format. Was hoping someone could take a look and see what I might be missing.
private void PlayIntroCinematic()
{
CreateCinematicPlayer();
PlayCinematicVideo();
}
private void CreateCinematicPlayer()
{
Camera videoPlayerCamera = (new GameObject("VideoPlayerCamera", typeof(DontDestroyOnLoad))).AddComponent<Camera>();
videoPlayerCamera.clearFlags = CameraClearFlags.SolidColor;
videoPlayerCamera.backgroundColor = Color.black;
videoPlayerCamera.gameObject.AddComponent<AudioListener>();
audioSource = videoPlayerCamera.gameObject.AddComponent<AudioSource>();
videoPlayer = videoPlayerCamera.gameObject.AddComponent<VideoPlayer>();
audioSource.playOnAwake = false;
videoPlayer.playOnAwake = false;
videoPlayer.renderMode = VideoRenderMode.CameraNearPlane;
videoPlayer.source = VideoSource.Url;
videoPlayer.url = GetVideoUrl();
videoPlayer.audioOutputMode = VideoAudioOutputMode.AudioSource;
videoPlayer.EnableAudioTrack(0, true);
videoPlayer.SetTargetAudioSource(0, audioSource);
}
private void PlayCinematicVideo()
{
videoPlayer.loopPointReached += OnIntroComplete;
videoPlayer.Play();
audioSource.Play();
}
Comment
Best Answer
Answer by jonAtNvizzio · Oct 11, 2018 at 03:31 PM
Found the issue. As well as the AudioSource setup that needed to be done I also needed to add this line:
videoPlayer.controlledAudioTrackCount = 1;
For context:
videoPlayer.audioOutputMode = VideoAudioOutputMode.AudioSource;
videoPlayer.controlledAudioTrackCount = 1;
videoPlayer.EnableAudioTrack(0, true);
videoPlayer.SetTargetAudioSource(0, audioSource);
Your answer
Follow this Question
Related Questions
Download video and put it into StreamingAssets folder 0 Answers
Manage AudioMixing with Video 0 Answers
playing audio from a video clip 0 Answers
Stream audio from a YouTube playlist's URL? 0 Answers
load video into mobile app 1 Answer