48 lines
1.2 KiB
C#
48 lines
1.2 KiB
C#
using System.Collections;
|
|
using System.Collections.Generic;
|
|
using RenderHeads.Media.AVProVideo;
|
|
using UnityEngine;
|
|
|
|
public class JK : MonoBehaviour
|
|
{
|
|
public MediaPlayer mediaPlayer; // 拖拽 MediaPlayer 组件到这个字段
|
|
|
|
// 要播放的视频 URL
|
|
private string videoUrl = "http://120.24.108.232:80/rtp/41010500002000000001_34020000001320000001.live.mp4";
|
|
|
|
void Start()
|
|
{
|
|
if (mediaPlayer != null)
|
|
{
|
|
StartCoroutine(PlayVideo());
|
|
}
|
|
else
|
|
{
|
|
Debug.LogError("MediaPlayer component is not assigned.");
|
|
}
|
|
}
|
|
public void LoadVideo()
|
|
{
|
|
if (mediaPlayer != null)
|
|
{
|
|
// 停止播放并关闭视频
|
|
mediaPlayer.Stop();
|
|
mediaPlayer.CloseMedia();
|
|
StartCoroutine(PlayVideo());
|
|
}
|
|
else
|
|
{
|
|
Debug.LogError("MediaPlayer component is not assigned.");
|
|
}
|
|
}
|
|
|
|
private IEnumerator PlayVideo()
|
|
{
|
|
mediaPlayer.OpenMedia(MediaPathType.AbsolutePathOrURL, videoUrl, true);
|
|
// 等待视频缓冲
|
|
yield return new WaitForSeconds(1f); // 可以调整等待时间
|
|
mediaPlayer.Play();
|
|
}
|
|
|
|
}
|