我正在努力从Unity Video Player中获取视频中的声音。
视频播放正常,但声音无效。
以下是我基于this线程使用的代码。
public VideoClip VideoClip;
private AudioSource audioSource;
private IEnumerator videoCoRoutine;
void Awake()
{
VideoPlayer videoPlayer = gameObject.AddComponent<VideoPlayer>();
audioSource = gameObject.AddComponent<AudioSource>();
videoPlayer.clip = VideoClip;
videoPlayer.source = VideoSource.VideoClip;
//videoPlayer.Prepare();
videoPlayer.renderMode = VideoRenderMode.CameraNearPlane;
videoPlayer.audioOutputMode = VideoAudioOutputMode.AudioSource;
videoPlayer.EnableAudioTrack(0, true);
videoPlayer.SetTargetAudioSource(0, audioSource);
videoPlayer.Play();
audioSource.Play();
//StartCoroutine(PlayVid());
ContinueBtn.onClick.AddListener(OnContinue);
}
有人可以帮忙吗?
由于
答案 0 :(得分:2)
通过反复试验,这是我发现在Windows 10上使用Unity 2017.1从C#播放VideoClip时需要调用的最小值:
public class VideoPlayerTest : MonoBehaviour {
public VideoPlayer player;
public VideoClip clip;
public AudioSource audioSource;
// Use this for initialization
void Start () {
player.audioOutputMode = VideoAudioOutputMode.AudioSource;
player.SetTargetAudioSource(0, audioSource);
player.source = VideoSource.VideoClip;
player.clip = clip;
player.Play();
}
}
使用如下配置的GameObject: Unity Editor Inspector 使用此MP4文件(下载并放入Assets目录): https://www.quirksmode.org/html5/videos/big_buck_bunny.mp4
祝你好运!我花了很多时间摆弄启用曲目/频道,在绊倒这个简单的配置之前似乎没有做任何事情。