Strange problem with MediaPool

Rosebud wrote on 1/7/2009, 8:19 AM
I have a problem I can’t to solve with the MediaPool.
When I add a media to the RootMediaBin, after that I ‘m not able to access to MediaPool.

Please try this simple CS script:

using System;
using Sony.Vegas;
using System.Windows.Forms;

public class EntryPoint
{
public void FromVegas(Vegas vegas)
{

MediaBin bin = vegas.Project.MediaPool.RootMediaBin;
Media media = new Media(@"D:\Essai\scene0005.avi");// replace with your own media

bin.Add(media);

foreach (MediaBin binScan in vegas.Project.MediaPool.RootMediaBin)
{
MessageBox.Show(binScan.Name);
}
}
}

Media is added but after I get this error:
“System.InvalidCastException: Unable to cast object of type 'Sony.Vegas.Media' to type 'Sony.Vegas.MediaBin'.”

Any help is welcome.
TIA
Gilles

Comments

Rosebud wrote on 1/7/2009, 11:30 PM
Ok, when I use the MediaPool.AddMedia() function, I have no problem.
So it seems we shouldn’t add media to the RootMediaBin.

Please Sony, can you confirm ?
Is it a bug ?
altarvic wrote on 1/10/2009, 9:28 PM

foreach (IMediaBinNode node in vegas.Project.MediaPool.RootMediaBin)
{
if (node.NodeType == MediaBinNodeType.Bin) MessageBox.Show(((MediaBin) node).Name);
}
Rosebud wrote on 1/10/2009, 11:26 PM
Thank you altarvic,

Now I would like to understand the difference between the RootMediaBin.Add() and the MediaPool.AddMedia() method.

Please, can you explain me why those two scripts don’t give the same result ?


using System;
using Sony.Vegas;
using System.Windows.Forms;

public class EntryPoint
{
public void FromVegas(Vegas vegas)
{
vegas.Project.MediaPool.AddMedia(@"D:\Essai\scene0005.avi");

foreach (IMediaBinNode binScan in vegas.Project.MediaPool.RootMediaBin)
{
MessageBox.Show(binScan.NodeType.ToString());
}
}
}



using System;
using Sony.Vegas;
using System.Windows.Forms;

public class EntryPoint
{
public void FromVegas(Vegas vegas)
{
MediaBin bin = vegas.Project.MediaPool.RootMediaBin;
Media media = new Media(@"D:\Essai\scene0005.avi");

bin.Add(media);

foreach (IMediaBinNode binScan in vegas.Project.MediaPool.RootMediaBin)
{
MessageBox.Show(binScan.NodeType.ToString());
}
}
}


Thx for your help.

Gilles
JohnnyRoy wrote on 1/11/2009, 6:48 AM
> Please, can you explain me why those two scripts don’t give the same result ?

Because they are not doing the same thing. The first is adding media to the MediaPool which does not associate the media with any bin. The second is explicitly adding the media to the RootMediaBin. That's why first version does not find the media in the RootMediaBin.

~jr
Rosebud wrote on 1/11/2009, 8:45 AM
Thx jr,

Since the RootMediabin is the top level media bin, I was thinking MediaPool and MediaPool.RootMediaBin were the same thing.
By the way, adding media to one or the other give the same “visual” Mediapool structure.
altarvic wrote on 1/11/2009, 8:12 PM
if you enumerate MediaPool instead of Root bin then above two scripts will give the same result

foreach (IMediaBinNode binScan in vegas.Project.MediaPool)
{
MessageBox.Show(binScan.NodeType.ToString());
}