3 using System.Collections.Generic;
5 using System.Threading;
7 using System.Runtime.InteropServices;
8 using Microsoft.Xna.Framework;
9 using Microsoft.Xna.Framework.Graphics;
14 partial class Video : IDisposable
16 private static Internal.EventCallback VideoFrameCallback;
17 private static Internal.EventCallback VideoAudioCallback;
19 private static Dictionary<IntPtr, Video> videos;
23 if (VideoFrameCallback ==
null)
25 VideoFrameCallback = VideoFrameUpdate;
28 if (VideoAudioCallback ==
null)
30 VideoAudioCallback = VideoAudioUpdate;
35 videos =
new Dictionary<IntPtr, Video>();
43 List<Video> vids = videos.Values.ToList();
44 foreach (
Video v
in vids)
51 private IntPtr videoInternal;
53 private Texture2D texture;
54 private bool textureChanged;
55 private Int32[] textureData;
61 public int Width {
get;
private set; }
62 public int Height {
get;
private set; }
66 get {
return sound ==
null ? 0.0f : sound.
BaseGain; }
67 set {
if (sound !=
null) { sound.
BaseGain = value; } }
74 Video video =
new Video(graphicsDevice, soundManager, filename);
79 private Video(GraphicsDevice graphicsDevice,
SoundManager soundManager,
string filename)
83 videoInternal = Internal.loadVideo(filename);
85 if (videoInternal == IntPtr.Zero) {
LoadFailed =
true;
return; }
89 Width = Internal.getVideoWidth(videoInternal);
Height = Internal.getVideoHeight(videoInternal);
91 texture =
new Texture2D(graphicsDevice, (
int)
Width, (
int)
Height);
96 textureData[i] = unchecked((
int)0xff000000);
98 texture.SetData(textureData);
100 videos.Add(videoInternal,
this);
102 IntPtr videoFrameCallbackPtr = Marshal.GetFunctionPointerForDelegate(VideoFrameCallback);
103 Internal.setVideoFrameCallback(videoInternal, videoFrameCallbackPtr);
104 IntPtr videoAudioCallbackPtr = Marshal.GetFunctionPointerForDelegate(VideoAudioCallback);
105 Internal.setVideoAudioCallback(videoInternal, videoAudioCallbackPtr);
108 if (Internal.videoHasAudio(videoInternal)==1)
110 int sampleRate = Internal.getVideoAudioSampleRate(videoInternal);
111 int channelCount = Internal.getVideoAudioChannelCount(videoInternal);
112 sound =
new VideoSound(soundManager, filename, sampleRate, channelCount,
this);
115 textureChanged =
false;
117 Internal.playVideo(videoInternal);
123 Internal.playVideo(videoInternal);
130 Internal.deleteVideo(videoInternal);
131 videos.Remove(videoInternal);
143 return Internal.isVideoPlaying(videoInternal)==1;
154 texture.SetData(textureData);
155 textureChanged =
false;
168 Marshal.Copy(data, textureData, 0, (
int)(
Width *
Height));
169 textureChanged =
true;
173 static void VideoFrameUpdate(IntPtr videoInternal, IntPtr data, Int32 dataElemSize, Int32 dataLen)
175 Video video = videos[videoInternal];
180 static void VideoAudioUpdate(IntPtr videoInternal, IntPtr data, Int32 dataElemSize, Int32 dataLen)
182 Video video = videos[videoInternal];
184 if (video.sound !=
null && dataLen > 0)
187 short[] newBuf =
new short[dataLen];
188 Marshal.Copy(data, newBuf, 0, dataLen);
override SoundChannel Play(float gain, float range, Vector2 position, bool muffle=false)
void Enqueue(short[] buf)
override bool IsPlaying()