TrackEvent' does not contain a definition for 'Media'?

YOUNHEE-LEE wrote on 11/28/2024, 8:27 AM

The code below has occurred an error on "mediaEvent.Media" part.

'TrackEvent' does not contain a definition for 'Media', and no accessible extension method 'Media' accepting a first argument of type 'TrackEvent'

I don't know why...

if (firstEvent is TrackEvent)
{
    TrackEvent mediaEvent = (TrackEvent)firstEvent;
    Media media = mediaEvent.Media;
    if (media != null && !string.IsNullOrEmpty(media.FilePath))
    { ...}

...

}

 

How can I fix this?

 

Comments

zzzzzz9125 wrote on 11/28/2024, 9:18 AM

Your code is confusing, and I'm not sure what you're trying to do.

Such as the first few lines:

if (firstEvent is TrackEvent)
{
    TrackEvent mediaEvent = (TrackEvent)firstEvent;

firstEvent should belong to the TrackEvent class. You don't need to make additional judgments about it, unless you want to determine whether it's a VideoEvent or an AudioEvent.

The line that reports the error:

Media media = mediaEvent.Media;

If you look closely at VEGAS Pro Scripting API Summary (online document here), you will see that TrackEvent does NOT have Media.

To access its media, you should use:

Media media = mediaEvent.ActiveTake.Media;

None of us can program at first, so we need to learn. If you don't have a basic knowledge of VEGAS Scripting, I recommend you visit http://www.jetdv.com/ for lots of learning references.

Last changed by zzzzzz9125 on 11/28/2024, 9:18 AM, changed a total of 1 times.

Using VEGAS Pro 22 build 248 & VEGAS Pro 21 build 208.

Information about my PC:
Brand Name: HP VICTUS Laptop
System: Windows 11.0 (64-bit) 10.00.22631
CPU: 12th Gen Intel(R) Core(TM) i7-12700H
GPU: NVIDIA GeForce RTX 3050 Laptop GPU
GPU Driver: NVIDIA Studio Driver 560.70

jetdv wrote on 11/28/2024, 9:24 AM

First of all, if you're looking at track events, the first event WILL be a TrackEvent so that "IF" is not needed. But how are you getting "firstEvent"?

To get the media of a track event, look at "ActiveTake.Media".

Here's an example that will get the media for any selected event on the timeline. What you do with that media once you have it is up to you.

            myVegas = vegas;

            foreach (Track myTrack in myVegas.Project.Tracks)
            {
                foreach(TrackEvent myEvent = myTrack.Events)
                {
                    if (myEvent.Selected)
                    {
                        Media myMedia = myEvent.ActiveTake.Media;
                    }
                }
            }

If you haven't, you might want to take a look at my scripting tutorials: