AVProWindowsMediaMovieFromResource.cs
2.04 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
using UnityEngine;
using System.Collections;
using System.IO;
using System.Runtime.InteropServices;
//-----------------------------------------------------------------------------
// Copyright 2012-2016 RenderHeads Ltd. All rights reserved.
//-----------------------------------------------------------------------------
[AddComponentMenu("AVPro Windows Media/Movie From Resource")]
public class AVProWindowsMediaMovieFromResource : AVProWindowsMediaMovie
{
private TextAsset _textAsset;
private GCHandle _bytesHandle;
public override void Start()
{
#if UNITY_EDITOR
if (!Application.isPlaying)
return;
#endif
if (null == AVProWindowsMediaManager.Instance)
{
throw new System.Exception("You need to add AVProWindowsMediaManager component to your scene.");
}
if (_loadOnStart)
{
LoadMovieFromResource(_playOnStart, _filename);
}
}
public override bool LoadMovie(bool autoPlay)
{
return LoadMovieFromResource(autoPlay, _filename);
}
public bool LoadMovieFromResource(bool autoPlay, string path)
{
bool result = false;
UnloadMovie();
_textAsset = Resources.Load(path, typeof(TextAsset)) as TextAsset;
if (_textAsset != null)
{
if (_textAsset.bytes != null && _textAsset.bytes.Length > 0)
{
_bytesHandle = GCHandle.Alloc(_textAsset.bytes, GCHandleType.Pinned);
result = LoadMovieFromMemory(autoPlay, path, _bytesHandle.AddrOfPinnedObject(), (uint)_textAsset.bytes.Length, FilterMode.Bilinear, TextureWrapMode.Clamp);
}
}
if (!result)
{
Debug.LogError("[AVProWindowsMedia] Unable to load resource " + path);
}
return result;
}
public override void UnloadMovie()
{
if (_moviePlayer != null)
{
_moviePlayer.Dispose();
_moviePlayer = null;
}
UnloadResource();
}
private void UnloadResource()
{
if (_bytesHandle.IsAllocated)
{
_bytesHandle.Free();
}
#if !UNITY_3_5
if (_textAsset != null)
{
Resources.UnloadAsset(_textAsset);
_textAsset = null;
}
#endif
}
}