VideoLan.Interop a .Net libvlc 0.9.x wrapper

This forum is about all development around libVLC.
lopez.tuparles
New Cone
New Cone
Posts: 6
Joined: 21 Dec 2008 20:25

Re: VideoLan.Interop a .Net libvlc 0.9.x wrapper

Postby lopez.tuparles » 20 Jul 2009 15:10

Hi,
As i undestand Vlc APi can't read playlist Stream. Is there a way to extract a list of Stream from a playlist with the API.
Thanks in advance.

if I pass the actual stream URL, the stream plays. ie the following works:
Code: Select all
string filename = "mms://wmlive-acl.bbc.co.uk/wms/bbc_ami/radio1/radio1_bb_live_eq1_sl0?BBC-UID=945a3082dec341e5dda25cfd113eaa3e1c94c2be00d0e1f4a42fa936cf8ec007&SSO2-UID="
but if I pass a playlist file the stream doesn't play. The same is true for winamp m3u files.
Code: Select all
string filename=http://www.bbc.co.uk/radio1/wm_asx/aod/radio1.asx
Both links play in a normal VLC instance.
What do I need to prepare the stream for playback?
Cheers
have anyone manage to solve this problem yet? I like this wrapper alot and it also works on 1.0.0
The only thing thatis bugging me is the inability to play online playlist

XilasZ
Developer
Developer
Posts: 189
Joined: 16 Jun 2009 20:35

Re: VideoLan.Interop a .Net libvlc 0.9.x wrapper

Postby XilasZ » 20 Jul 2009 15:51

Hi,
As i undestand Vlc APi can't read playlist Stream. Is there a way to extract a list of Stream from a playlist with the API.
Thanks in advance.
i don't use them, but maybe the functions named libvlc_media_list_* can do it. Try the VlcMediaList class, maybe it works (i didn't try them)

Kairos
Blank Cone
Blank Cone
Posts: 45
Joined: 01 Mar 2008 01:49
Operating System: Windows
Location: Scottsdale, Az
Contact:

Re: VideoLan.Interop a .Net libvlc 0.9.x wrapper

Postby Kairos » 21 Jul 2009 03:54

try to remove "--plugin-path", i noticed that since 1.0, libvlc crash with that option. just let the plugin folder with libvlc (the same way they are in vlc)
I was having the same problem where vlc would crash in the first few seconds of playing any file. Although I don't understand why, removing the plugin-path worked for me.

tamiro44
Cone that earned his stripes
Cone that earned his stripes
Posts: 131
Joined: 15 Feb 2009 15:21

Re: VideoLan.Interop a .Net libvlc 0.9.x wrapper

Postby tamiro44 » 21 Jul 2009 07:58

Hi,
How can you force your player to adjust the movie resolution?
After the player handle passed to the form, it won't change automatically.
Can i find out from API the movie's resolution?

Tamir.

Mongrel
Blank Cone
Blank Cone
Posts: 11
Joined: 12 Jul 2009 11:35

Re: VideoLan.Interop a .Net libvlc 0.9.x wrapper

Postby Mongrel » 21 Jul 2009 14:43

try to remove "--plugin-path", i noticed that since 1.0, libvlc crash with that option. just let the plugin folder with libvlc (the same way they are in vlc)
I was having the same problem where vlc would crash in the first few seconds of playing any file. Although I don't understand why, removing the plugin-path worked for me.
I'll try it this evening.

Edit: Jup, that's it. No more crashes.
Thanks Xilas!

Kairos
Blank Cone
Blank Cone
Posts: 45
Joined: 01 Mar 2008 01:49
Operating System: Windows
Location: Scottsdale, Az
Contact:

Re: VideoLan.Interop a .Net libvlc 0.9.x wrapper

Postby Kairos » 22 Jul 2009 08:35

Just a warning, I've started adding in the new 1.0.0 functionality into this wrapper. So if your going to use the 1.0.0 branch on my svn then just be aware its still in development.

shultas
New Cone
New Cone
Posts: 1
Joined: 24 Jul 2009 17:37

Re: VideoLan.Interop a .Net libvlc 0.9.x wrapper

Postby shultas » 24 Jul 2009 23:57

Hi There-

First off, awesome job on this wrapper! I spent days trying to figure out how to play a MPEG-4 file (I'm a newb, I suck at this point), but about 10 minutes getting it to work with your library, so thank you!

I have a question. I have adapted it to work with two video windows side by side for an application I am trying to write. Basically lets the user load two files and play them back at the same time so they can analyze them side by side. It works pretty good for the most part. On occasion if I call things such as "VlcPlayer.WillPlay" (if a video is loaded or not loaded) it will crash the app and tell me something about it couldn't read protected memory. Those little kinks I can work out, but there is one thing I just cannot figure out.

I have two instances of the VideoLanClient and VlcMediaPlayer, one for each Panel/Video Window. The Player.Mute = true, and = false does not work properly all the time for me. I have two buttons on my form, all they do is "VlcPlayerLeftWindow.Audio.Mute = !VlcPlayerLeftWindow.Audio.Mute". I press play, the videos begin to play, and I press the mute button. Sometimes it works, sometimes it does not. I've found that if you click like a mad man in different combinations, it will get it to start working again. The other issue that I am having ... I only want audio from the first VlcPlayer to be heard. I have a Play button. On the play button it calls VlcPlayerLeftWindow.Play(); then VlcPlayerRightWindow.Play(); If I set VlcPlayerRightWindow.Audio.Mute = true in this code event, the audio mutes for both players. However, if I put a Thread.Sleep(1000) in there, causing the program to wait for a second after the video starts playing, and then call Mute, it will mute only that one channel (most of the time). I cannot figure out what I am doing wrong, any help would be appreciated.

Here's what I've done:

VlcLeftWindow = new VideoLanClient();
VlcRightWindow = new VideoLanClient();
VlcPlayerLeftWindow = VlcLeftWindow.NewMediaPlayer(panelVideoLeftWindow.Handle);
VlcPlayerRightWindow = VlcRightWindow.NewMediaPlayer(panelVideoRightWindow.Handle);

-- Load Click Code, Left Window--
if (OpenFile.ShowDialog() == DialogResult.OK)
{
VlcMedia desc = VlcLeftWindow.NewMedia(OpenFile.FileName);
VlcPlayerLeftWindow.Load(desc);
desc.Dispose();
}

-- Load Click Code, Right Window--
if (OpenFile.ShowDialog() == DialogResult.OK)
{
VlcMedia desc = VlcRightWindow.NewMedia(OpenFile.FileName);
VlcPlayerRightWindow.Load(desc);
desc.Dispose();
}


-- Play Click Code ---
// if ( (VlcPlayerLeftWindow.WillPlay) && (VlcPlayerRightWindow.WillPlay)) // Took this line out, because it crashes the program when a file is not loaded.

VlcPlayerLeftWindow.Play();
VlcPlayerRightWindow.Play();
VlcPlayerRightWindow.Audio.Mute = true; // This causes audio from VlcPlayerLeftWindow AND VlcPlayerRightWindow to mute
// Thread.Sleep(1000);
// VlcPlayerRightWindow.Audio.Mute = true; // This sometimes works and will only mute the right window's associated audio

-- Mute Click Code, Left --
VlcPlayerLeftWindow.Audio.Mute = !VlcPlayerLeftWindow.Audio.Mute; // Sometimes works, sometimes it doesn't

--Mute Click Code, Right --
VlcPlayerRightWindow.Audio.Mute = !VlcPlayerRightWindow.Audio.Mute; // Sometimes works, sometimes it doesn't

EDIT: I also tried all of this by using only one VideoLanClient and still cannot get the audio to mute and unmute reliably.

Kairos
Blank Cone
Blank Cone
Posts: 45
Joined: 01 Mar 2008 01:49
Operating System: Windows
Location: Scottsdale, Az
Contact:

Re: VideoLan.Interop a .Net libvlc 0.9.x wrapper

Postby Kairos » 26 Jul 2009 19:39

Wow, a lot of problems. Your first problem is something I find out only after creating VideoLan.Interop, you can only create a single VideoLanClient object. Essentially the second object overwirites the first object and is the cause of the unexpected results. This could be the cause of many of the other problems like reading protected memory. To use multiple players, create a single VideoLanClient, and use that same object to create 2 VlcMediaPlayers.

Your second problem stems from the first problem. If you look at my code I sometimes call methods with p_media_player (pointer to a media player object) and other times p_instance (pointer to the vlc instance). When a method uses p_media_player, that method is specific to the media player you call it from. When a method uses p_instance then that method is global among all media player instances. Mute is one of those methods that uses p_instance, so it should mute all media players. Calling it twice like in your code should actually mute it first, then unmute it the second time.

ekennedy
Blank Cone
Blank Cone
Posts: 38
Joined: 18 Sep 2008 22:05
VLC version: 1.0
Operating System: Windows
Location: Texas

Re: VideoLan.Interop a .Net libvlc 0.9.x wrapper

Postby ekennedy » 28 Jul 2009 16:00

I just wrote a simple 100% native player using one of the tutorials in the wiki and even that one crashes after the first frame. Can anyone confirm that libvlc is actually working right now? I'm using Windows 7 64bit, but I also tried this in a virtual machine with Windows XP 32 with the same result. The normal VLC player works fine.
I built a wrapper using MFC (I can here the howling already!) and it's not crashing on WinXP or Vista 64-bit. I haven't tried Win7 yet. I'm planning on posting a sample somewhere soon.

I created a lib file from libvlc.dll then created a wrapper.

ed

Mongrel
Blank Cone
Blank Cone
Posts: 11
Joined: 12 Jul 2009 11:35

Re: VideoLan.Interop a .Net libvlc 0.9.x wrapper

Postby Mongrel » 28 Jul 2009 17:11

I just wrote a simple 100% native player using one of the tutorials in the wiki and even that one crashes after the first frame. Can anyone confirm that libvlc is actually working right now? I'm using Windows 7 64bit, but I also tried this in a virtual machine with Windows XP 32 with the same result. The normal VLC player works fine.
I built a wrapper using MFC (I can here the howling already!) and it's not crashing on WinXP or Vista 64-bit. I haven't tried Win7 yet. I'm planning on posting a sample somewhere soon.

I created a lib file from libvlc.dll then created a wrapper.

ed
The issue with the crashes has been resolved already. Adding the "plugin-path" option to libvlc makes it really unstable. Removing it is the way to go.

XilasZ
Developer
Developer
Posts: 189
Joined: 16 Jun 2009 20:35

Re: VideoLan.Interop a .Net libvlc 0.9.x wrapper

Postby XilasZ » 29 Jul 2009 17:04

Kairos, did you managed to get event data correctly (position in a PositionChangedEvent) with 1.0.x ?
It worked with libvlc 0.9, but with 1.0.x, i got bad values (currently, i got something like 2E-44, almost 0).
I modified event class according to changes in libvlc (i looked to changes in vlc's git reposititory).
With or without those changes, nothing works.

By the way, your last commit message says : "Finished implementing tracks, though not all work due to bugs in libvlc". What part exactly ? i'm using tracks for audio/video/subtitles, and everything is working fine.

PS: i'm using your wrapper 0.9, that i upgraded myself to 1.0 before you, maybe i did something wrong

Kairos
Blank Cone
Blank Cone
Posts: 45
Joined: 01 Mar 2008 01:49
Operating System: Windows
Location: Scottsdale, Az
Contact:

Re: VideoLan.Interop a .Net libvlc 0.9.x wrapper

Postby Kairos » 29 Jul 2009 21:53

Kairos, did you managed to get event data correctly (position in a PositionChangedEvent) with 1.0.x ?
It worked with libvlc 0.9, but with 1.0.x, i got bad values (currently, i got something like 2E-44, almost 0).
I modified event class according to changes in libvlc (i looked to changes in vlc's git reposititory).
With or without those changes, nothing works.
I didn't know the events were broken. I'll look at it when I get a chance.
By the way, your last commit message says : "Finished implementing tracks, though not all work due to bugs in libvlc". What part exactly ? i'm using tracks for audio/video/subtitles, and everything is working fine.
You could always change tracks, but now you can get the description for each track. For this reason I revamped how tracks are handled and gave each track (subtitle, title, chapter, audio, and video) a separate class to wrap track specific functions. I still need to iron out my own bugs like when to load descriptions, but the problem in vlc I was referring to was here viewtopic.php?f=32&t=62686. Also when testing the subtitle tracks, I noticed every video with a subtitle I tested would crash on loading. I've only tried 1.0.0 release. It may have been fixed I don't know.

XilasZ
Developer
Developer
Posts: 189
Joined: 16 Jun 2009 20:35

Re: VideoLan.Interop a .Net libvlc 0.9.x wrapper

Postby XilasZ » 29 Jul 2009 22:06

Hmm ok. now i remember, i noticed that get/set are strange, see here : viewtopic.php?f=33&t=60943#p203685 , last post (don't bother with deinterlace or the issue at the end, i wasn't doing thing right).

some works with the index in the track list, the others works with the real id.

my modified wrapper take those strange things into account. But i did this before the official release with 1.0 rc4. now with 1.0.1, i should test again, maybe it's fixed.

Edit: i just tested, video_get_track give an index, while video_set_track need the real id. nothing seems to be changed in 1.0.1
Also when testing the subtitle tracks, I noticed every video with a subtitle I tested would crash on loading. I've only tried 1.0.0 release. It may have been fixed I don't know.
An avi with an srt subtitle file works perfectly for me, i can switch all tracks (audio/video/subtitle) on/off without issue (thanks to my wrapper which use it the id or the index, depending on the function to call). But i noticed that vlc crashes if it's an ass subtitle file.

nisha
New Cone
New Cone
Posts: 1
Joined: 31 Jul 2009 11:09

Re: VideoLan.Interop a .Net libvlc 0.9.x wrapper

Postby nisha » 31 Jul 2009 11:15

Is VLM working in latest interop 1.0.0 wrapper. How can i use it to broadcast more then 1 stream.

XilasZ
Developer
Developer
Posts: 189
Joined: 16 Jun 2009 20:35

Re: VideoLan.Interop a .Net libvlc 0.9.x wrapper

Postby XilasZ » 05 Aug 2009 14:09

Hi, kairos, there is a small bug in the wrapper when using libvlc_media_get_meta.

It seems that libvlc returns an ansi string, while .NET is trying to map the return value as a unicode string, so it crash (memory protected error).
To fix this, just add "[return:MarshalAs(UnmanagedType.AnsiBStr)]" before the function declaration.

Code: Select all

[return:MarshalAs(UnmanagedType.AnsiBStr)] internal static extern String libvlc_media_get_meta(.....);
By the way, i may have fixed my random crash issue after reading this : viewtopic.php?f=32&t=62504&start=0&hilit=delphi
When calling stop or exiting the program, it seems libvlc can crash if libvlc is still linked to a display surface.
I was setting the surface only once at startup, and i never broke the link to libvlc. I think that's the cause of my random crashes at exit or when calling stop.
Now i set the display surface when starting playing something, and remove it as soon as it stops. Since i did that, i got 0 crash.

I also tried to use the mediametachanged events, but nothing works. as soon as the event is fired, i got a memory protected error, i guess there is something wrong between libvlc and .net, probably a type mismatch. did you manage to make events work with 1.0.x ?

Miracle
New Cone
New Cone
Posts: 5
Joined: 16 Aug 2009 20:04

Re: VideoLan.Interop a .Net libvlc 0.9.x wrapper

Postby Miracle » 17 Aug 2009 19:02

Hi Kairos,
As a hobby, I am developing a small application to play, record, split and join video files. This all works using your 0.9 wrapper which is much appreciated. The issue I have right now is with a film strip timeline I have added on to show 100 stills / frames at equally spaced time intervals. The problem is that vlcmediaplayer.video.width and height take much longer to retrieve than vlcmediaplayer.length even though all three are subject to a VlcState.Playing = true test polled for through a timer. The length is returned as soon as play commences but the width and height seems to take up to 6 seconds from the start of play. I tried a Do Until approach wrapped in a Try Catch but I can't seem to avoid a 'read / write to protected memory' error. For the moment, I have put in a 6 second Thread.Sleep in the main UI thread before making the width and height calls to avoid the constant crashes.

Does it make sense to you that the width and height calls should take so long ?

If it does, is there an elegant way to catch the protected memory error so that the Do Until can continue looping until the width and height 'arrive' ?

Appreciate anyone's help.

Septic
New Cone
New Cone
Posts: 3
Joined: 07 Sep 2009 22:33

Re: VideoLan.Interop a .Net libvlc 0.9.x wrapper

Postby Septic » 07 Sep 2009 22:40

[Edit]
Has anybody noticed the Mistake in VlcMediaEnumerator?

Movenext: return (++_index >= _mlist.Count); --> return (++_index < _mlist.Count);


I also have problems with Chapters

libvlc_video_get_chapter_description --> crashes with AccessViolationException - any Idea?

[Originalmessage:]
[Solved: DAMNIT!! I Should really read the whole thread xD
added [return:MarshalAs(UnmangedType.AnsiBStr)] for
libvlc_exception_get_message
libvlc_media_get_meta
libvlc_media_get_mrl
]
Hi,

i have problems calling libvlc_media_get_mrl and libvlc_media_get_meta with the .net wrapper, i always get a AccessViolationException


anybody has a solution?

jmhecker
New Cone
New Cone
Posts: 3
Joined: 12 Sep 2009 19:32

Re: VideoLan.Interop a .Net libvlc 0.9.x wrapper

Postby jmhecker » 12 Sep 2009 22:18

I am currently working on a small media player (just for fun), and am wondering if there is any way to handle mouse events with this wrapper? Once VlcPlayer takes over the panel control, no mouse events work on that control, so it seems to me that any right-click functionality is lost (for using a custom context menu).

Can anyone offer any ideas/advice?

Below is how I call the wrapper (yes, it is vb.net, but post replies in C# if need be, I use both)


Vlc = New VideoLanClient()
Dim desc As VlcMedia = Vlc.NewMedia("C:\21.avi")
VlcPlayer = Vlc.NewMediaPlayer(Panel1.Handle, desc)
desc.Dispose()
VlcPlayer.Play().


EDIT:

So, I tried to create a custom control, which houses the Panel that the VLC library uses, and added that to my form...I put a context menu onto the custom control (from the parent window, not the custom control itself) hoping it would work...still not working.

XilasZ
Developer
Developer
Posts: 189
Joined: 16 Jun 2009 20:35

Re: VideoLan.Interop a .Net libvlc 0.9.x wrapper

Postby XilasZ » 13 Sep 2009 23:14

try to "disable" the panel, or put the panel inside another control, which is disabled.

In my case, i use WPF, so i got the panel is inside a "WindowsFormsHost", which is disabled. Vlc can still work with the panel and display the video inside, but any mouse interaction is ignored by the "WindowsFormsHost" and everything inside. So mouse actions go through the "WindowsFormHost", and reach the window behind and its context menu.

Miracle
New Cone
New Cone
Posts: 5
Joined: 16 Aug 2009 20:04

Re: VideoLan.Interop a .Net libvlc 0.9.x wrapper

Postby Miracle » 18 Sep 2009 20:11

Hi XilasZ,
Please could you help me out with libvlc_media_get_meta. I am trying out what you suggested and have included the MarshallAs as follows:

[DllImport("libvlc")][return: MarshalAs(UnmanagedType.AnsiBStr)]
internal static extern String libvlc_media_get_meta(etc...);.

However, I still get the protected memory error. What am I doing wrong ?

XilasZ
Developer
Developer
Posts: 189
Joined: 16 Jun 2009 20:35

Re: VideoLan.Interop a .Net libvlc 0.9.x wrapper

Postby XilasZ » 21 Sep 2009 10:10

Maybe the get_meta is not causing the error.

The protected memory error can happen for many many reasons, wrong timing when calling a libvlc function (for instance, don't try to get info on the media while nothing is playing, it fails, and it's normal), a type mismatch between c# and libvlc, wrong pointer arguments for a function (don't use the instance pointer instead the media player pointer, and vice versa), ....

If you are sure that get_meta is causing the error, how and when do you call it ?

Miracle
New Cone
New Cone
Posts: 5
Joined: 16 Aug 2009 20:04

Re: VideoLan.Interop a .Net libvlc 0.9.x wrapper

Postby Miracle » 22 Sep 2009 18:13

I am actually calling ReadMeta 3 seconds after a particular song has started to play, using <vlcmedia>.ReadMeta(libvlc_meta_t.libvlc_meta_Artist). Here is a summary of the relevant code in VB:

Dim vlcControl As VideoLan.VideoLanClient
vlcControl = New VideoLanClient(".")
Dim aaChannelDesc As VlcMedia = vlcControl.NewMedia(aaIncomingPathFileName)
... add some options and play, then 3 seconds later:

Dim strSongMeta as String = aaChannelDesc.ReadMeta(libvlc_meta_t.libvlc_meta_Title)

The last line above results in a protected memory error on the first line of the ReadMeta sub in vlcMedia.cs which is
string rtn = InteropMethods.libvlc_media_get_meta(p_media, tag, ref p_exception);

Does this throw any light on the problem ? I'm obviously doing something wrong but can't figure out where. I should also mention that I have a similar protected memory problem retrieving vlcmediaplayer.video.width. which I have described about 6 posts above. Maybe they are connected.

XilasZ
Developer
Developer
Posts: 189
Joined: 16 Jun 2009 20:35

Re: VideoLan.Interop a .Net libvlc 0.9.x wrapper

Postby XilasZ » 23 Sep 2009 11:33

it should be ok.

I see that you use libvlc 0.9 ? I didn't try to read meta when i was still using 0.9.
Now i'm using libvlc 1.0.1, after upgrading the wrapper myself. maybe read meta doesn't work in libvlc 0.9. Or i fixed something else in the wrapper, but don't know where :P

Take a look at my code if you want, you may found a clue.

noknok
Blank Cone
Blank Cone
Posts: 30
Joined: 08 Sep 2009 23:06

Re: VideoLan.Interop a .Net libvlc 0.9.x wrapper

Postby noknok » 25 Sep 2009 18:29

I have been using the VideoLan Interop on VLC 1.0.0,1.0.1 and now 1.0.2...

When trying to .DISPOSE on the PLAYER object, AFTER it has ended, the hangds in the COM layer.

This occurs as in the Dispose method of the player, it calls .STOP, no matter the current state.

Not sure how to (a) submit recommended changes to the source (b) report a bug so you can can do the changes.

Shawn

Miracle
New Cone
New Cone
Posts: 5
Joined: 16 Aug 2009 20:04

Re: VideoLan.Interop a .Net libvlc 0.9.x wrapper

Postby Miracle » 26 Sep 2009 17:40

XilasZ: thanks for your help and for letting me look at your code. It was interesting for me to see that you can obtain the song name by calling ReadMeta after Load and before Play Anyway, I still can't get it work for me on vlc 0.9. As an interim measure, I have obtained what I need using a background instance of Windows Media Player.


Return to “Development around libVLC”

Who is online

Users browsing this forum: No registered users and 54 guests