Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Don't throw exception for missing Video until its played #6

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion src/Content/ContentReaders/VideoReader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -41,10 +41,11 @@ Video existingInstance
/* The path string includes the ".wmv" extension. Let's see if this
* file exists in a format we actually support...
*/
string origpath = path;
path = Normalize(path.Substring(0, path.Length - 4));
if (String.IsNullOrEmpty(path))
{
throw new ContentLoadException();
path = origpath;
}

int durationMS = input.ReadObject<int>();
Expand Down
68 changes: 39 additions & 29 deletions src/Media/Xiph/Video.cs
Original file line number Diff line number Diff line change
Expand Up @@ -89,38 +89,41 @@ internal Video(string fileName, GraphicsDevice device)

Theorafile.th_pixel_fmt fmt;
Theorafile.tf_fopen(fileName, out theora);
Theorafile.tf_videoinfo(
theora,
out yWidth,
out yHeight,
out fps,
out fmt
);
if (fmt == Theorafile.th_pixel_fmt.TH_PF_420)
{
uvWidth = yWidth / 2;
uvHeight = yHeight / 2;
}
else if (fmt == Theorafile.th_pixel_fmt.TH_PF_422)
{
uvWidth = yWidth / 2;
uvHeight = yHeight;
}
else if (fmt == Theorafile.th_pixel_fmt.TH_PF_444)
{
uvWidth = yWidth;
uvHeight = yHeight;
}
else
if (theora != IntPtr.Zero)
{
throw new NotSupportedException(
"Unrecognized YUV format!"
Theorafile.tf_videoinfo(
theora,
out yWidth,
out yHeight,
out fps,
out fmt
);
}
if (fmt == Theorafile.th_pixel_fmt.TH_PF_420)
{
uvWidth = yWidth / 2;
uvHeight = yHeight / 2;
}
else if (fmt == Theorafile.th_pixel_fmt.TH_PF_422)
{
uvWidth = yWidth / 2;
uvHeight = yHeight;
}
else if (fmt == Theorafile.th_pixel_fmt.TH_PF_444)
{
uvWidth = yWidth;
uvHeight = yHeight;
}
else
{
throw new NotSupportedException(
"Unrecognized YUV format!"
);
}

// FIXME: This is a part of the Duration hack!
Duration = TimeSpan.MaxValue;
needsDurationHack = true;
// FIXME: This is a part of the Duration hack!
Duration = TimeSpan.MaxValue;
needsDurationHack = true;
}
}

internal Video(
Expand All @@ -136,6 +139,13 @@ VideoSoundtrackType soundtrackType
Duration = TimeSpan.FromMilliseconds(durationMS);
needsDurationHack = false;

if (theora == IntPtr.Zero)
{
yWidth = width;
yHeight = height;
fps = framesPerSecond;
}

VideoSoundtrackType = soundtrackType;
}

Expand Down
9 changes: 9 additions & 0 deletions src/Media/Xiph/VideoPlayer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -594,6 +594,15 @@ public Texture2D GetTexture()

public void Play(Video video)
{
if (video == null)
{
throw new System.ArgumentNullException();
}
if (video.theora == IntPtr.Zero)
{
throw new System.ArgumentException();
}

checkDisposed();

// We need to assign this regardless of what happens next.
Expand Down
Loading