public Video(GraphicsDevice graphicsDevice, SoundManager soundManager, string filename, uint width, uint height) { Init(); mutex = new object(); sound = new VideoSound(soundManager, filename, 44100, this); videos.Add(latestVideoId, this); videoId = latestVideoId; latestVideoId++; /*using (var stream = File.OpenRead(filename)) * {*/ byte[] filenameBytes = Encoding.UTF8.GetBytes(filename + "\0"); byte[] filenameBytesNullTerminated = new byte[filenameBytes.Length + 1]; filenameBytesNullTerminated[filenameBytes.Length] = 0; Array.Copy(filenameBytes, filenameBytesNullTerminated, filenameBytes.Length); media = LibVlcWrapper.LibVlcMethods.libvlc_media_new_path(lib, filenameBytesNullTerminated); LibVlcWrapper.LibVlcMethods.libvlc_media_parse(media); mediaPlayer = LibVlcWrapper.LibVlcMethods.libvlc_media_player_new(lib); LibVlcWrapper.LibVlcMethods.libvlc_media_player_set_media(mediaPlayer, media); //LibVlcWrapper.LibVlcMethods.libvlc_media_release(media); //LibVlcWrapper.LibVlcMethods.libvlc_video_get_size(mediaPlayer, 0, out width, out height); CrossThread.RequestExecutionOnMainThread(() => { texture = new Texture2D(graphicsDevice, (int)width, (int)height); }); Width = width; Height = height; unmanagedData = Marshal.AllocHGlobal(sizeof(int) * 2 + (int)(width * height * 3)); int[] arr = { videoId, 1 }; Marshal.Copy(arr, 0, unmanagedData, 2); textureData = new byte[width * height * 3]; for (int i = 0; i < width * height * 3; i++) { textureData[i] = 0; } IntPtr videoLockDelegatePtr = Marshal.GetFunctionPointerForDelegate(VideoLockDelegate); IntPtr videoUnlockDelegatePtr = Marshal.GetFunctionPointerForDelegate(VideoUnlockDelegate); IntPtr videoDisplayDelegatePtr = Marshal.GetFunctionPointerForDelegate(VideoDisplayDelegate); LibVlcWrapper.LibVlcMethods.libvlc_video_set_callbacks(mediaPlayer, videoLockDelegatePtr, videoUnlockDelegatePtr, videoDisplayDelegatePtr, unmanagedData); LibVlcWrapper.LibVlcMethods.libvlc_video_set_format(mediaPlayer, Encoding.UTF8.GetBytes("RV24\0"), (int)width, (int)height, (int)width * 3); IntPtr audioPlayDelegatePtr = Marshal.GetFunctionPointerForDelegate(AudioPlayDelegate); IntPtr audioPauseDelegatePtr = Marshal.GetFunctionPointerForDelegate(AudioPauseDelegate); IntPtr audioResumeDelegatePtr = Marshal.GetFunctionPointerForDelegate(AudioResumeDelegate); IntPtr audioFlushDelegatePtr = Marshal.GetFunctionPointerForDelegate(AudioFlushDelegate); IntPtr audioDrainDelegatePtr = Marshal.GetFunctionPointerForDelegate(AudioDrainDelegate); LibVlcWrapper.LibVlcMethods.libvlc_audio_set_callbacks(mediaPlayer, audioPlayDelegatePtr, audioPauseDelegatePtr, audioResumeDelegatePtr, audioFlushDelegatePtr, audioDrainDelegatePtr, unmanagedData); LibVlcWrapper.LibVlcMethods.libvlc_audio_set_format(mediaPlayer, Encoding.UTF8.GetBytes("S16N\0"), 44100, 2); LibVlcWrapper.LibVlcMethods.libvlc_audio_set_delay(mediaPlayer, 0); LibVlcWrapper.LibVlcMethods.libvlc_media_player_play(mediaPlayer); //} }
private Video(GraphicsDevice graphicsDevice, SoundManager soundManager, string filename) { Init(); videoInternal = Internal.loadVideo(filename); if (videoInternal == IntPtr.Zero) { LoadFailed = true; return; } mutex = new object(); Width = Internal.getVideoWidth(videoInternal); Height = Internal.getVideoHeight(videoInternal); texture = new Texture2D(graphicsDevice, (int)Width, (int)Height); textureData = new Int32[Width * Height]; for (int i = 0; i < Width * Height; i++) { textureData[i] = unchecked ((int)0xff000000); } texture.SetData(textureData); videos.Add(videoInternal, this); IntPtr videoFrameCallbackPtr = Marshal.GetFunctionPointerForDelegate(VideoFrameCallback); Internal.setVideoFrameCallback(videoInternal, videoFrameCallbackPtr); IntPtr videoAudioCallbackPtr = Marshal.GetFunctionPointerForDelegate(VideoAudioCallback); Internal.setVideoAudioCallback(videoInternal, videoAudioCallbackPtr); sound = null; if (Internal.videoHasAudio(videoInternal) == 1) { int sampleRate = Internal.getVideoAudioSampleRate(videoInternal); int channelCount = Internal.getVideoAudioChannelCount(videoInternal); sound = new VideoSound(soundManager, filename, sampleRate, channelCount, this); } textureChanged = false; Internal.playVideo(videoInternal); }