VLC to be my music player - who has made one? How to?

Here’s what I put into my app open

#If DebugBuild Then dim f,f1 as FolderItem f1=app.ExecutableFile.Parent f=SpecialFolder.ApplicationData.child("Guitar SightReader Toolbox").child("VLC").child("plugins") CopyFileOrFolder(f,f1) f=SpecialFolder.ApplicationData.child("Guitar SightReader Toolbox").child("VLC").child("libvlc.dll") f.CopyFileTo(f1) f=SpecialFolder.ApplicationData.child("Guitar SightReader Toolbox").child("VLC").child("libvlccore.dll") f.CopyFileTo(f1) #Endif

[quote=267129:@Sean Clancy]say I have f as a folderitem and it’s path is to a music file (like an mp3)

What’s the easiest way to load the music file into VLC?[/quote]

Put a VLCMediaPlayer control and a pushbutton on a window. In the pushbutton.action event:

   Dim f As FolderItem ' assume a valid folderitem for an MP3
   VLCMediaPlayer1.Media = f ' assign the folderitem to the Media property of the player control
   VLCMediaPlayer1.Play() ' begin playback

You can also use a URL string, e.g.:

  VLCMediaPlayer1.Media = "http://www.example.com/foo.mp3"
  VLCMediaPlayer1.Play()

Thanks… however…

I keep getting player.lengthMS=-1 - I presume this is the duration? What am I doing wrong?
f is pointing at a music file as a folderitem

Player.Media = f msgbox str(player.LengthMS) dim duration as Double = player.LengthMS

Just on an (important) side note:

You are aware if you include VLC in your app, it is bound to have issues with patents? So make sure you clear the codecs you are using (which can cost you a lot and may have an impact on setting the correct price for your app). Trust me, we looked into this years ago by asking (read: paying) a lawer to check this out. Audio and Video codecs are a mine field and you can come in big trouble using them without clearing them.

That said, when you use Apples AVFoundation, you should be cleared from this. So whenever possible, use those for video and audio features. Of course they do not cover all codecs (Xvid, VP8, VP9, Theora, …) and containers (MKV, AVI,Webm, …).

yeah this is for windows … I;m using Avfoundation for the Mac version

Plus… it’s only for audio and not video - The use will be fully the users resources and not shared. All irrelevant codecs of any note I’ll be deleting from the plugins folder.

player.LengthMS only works while the player is playing. Use the DurationMS property of the Media instead:

Player.Media = f
msgbox str(player.Media.DurationMS)
dim duration as Int64 = player.Media.DurationMS

As long you do not use AAC, AC3, MP3, DTS you’ll be fine. PCM (in a WAV container) and Ogg (any container) are the only audio codecs that are not covered by patents.

[quote=266360:@Sean Clancy]An exception of class libvlc.VLCException was not handled. The application must shut down.

Exception message: Volume percent is out of range (0-100)[/quote]

I figured it out. The player can’t change things like the volume, position, etc. until playback has begun. I’m not sure whether I’ll try to code around this limitation, but now that I know the problem I can at least stop raising an exception for it.

I get results when it was playing, but couldn’t change the position when not playing… that explains it :slight_smile:

I got it playing alright. I have 2 points in my wave file.
Point 1 is where it starts playback from in the audio file. The variable is called start
Point 2 is when the audio playback stops. the variable is called audioend
Both are doubles that represent seconds.

The mystery for me how player.TimeMS, player.lengthMS, player.media.DurationMS, Player.position are represented in time.
I usually get some astronomical 6 digit number. I also display the start and audioend points in minutes (2:45 for example).

If I want the playback to start from a certain point, I have to have
player.play
player,position = start
Player.volume = LLvol
player.speed = LLrate

The speed and the volume work well while it’s playing. The hard thing is setting the start position. I don’t use a slider, I use a graphic of a wavefile with a bar moving across it (a timer fires and puts the bar according to player.TimeMS)

Andrew - you are a guru for putting this together! It’s going to be way better than Windows media player and a nice replacement for quicktime (minus the recording which can be done with portaudio)

[quote=267306:@Sean Clancy]The mystery for me how player.TimeMS, player.lengthMS, player.media.DurationMS, Player.position are represented in time.
I usually get some astronomical 6 digit number.[/quote]

TimeMS, DurationMS, and LengthMS are in milliseconds (1000=1sec.) as an Int64. The Position is a percentage of the whole length expressed as a Single between 0.0 and 1.0, such that a Position of 0.1234 is 12.34% of the total length (IDK why they chose to do it that way.)

Andrew - you are a guru for putting this together! It's going to be way better than Windows media player and a nice replacement for quicktime (minus the recording which can be done with portaudio)

Thanks! And libvlc can do recording/transcoding. I haven’t quite got it figured out yet, but basically VLC command line parameters are applied to the Media, changing what the Player will do. For example this (should) convert an OGG file into and MP3.

As you can see, the command line parameters are pretty complex, and I don’t really understand them yet (these were copied from the docs), but it seems libvlc can do pretty much anything the VLC application can do.

that position thing is really weird isn’t it! I don’t think I would have ever figured it out myself!
But is it true that the position to play from can only be set after playing begins?

According to the docs setting the position has no effect unless its already playing.

It’s probably just as the VLC-player works: start playing, pause, choose position and resume playing.

Cool - Once I’ve got this going, I’m going to put together a complete tutorial on it to get it going for playing - steps and points.
My latest thing is working out the 1.0 percent thing as it applies to points in seconds. I thing it would be best do do this as a function which returns the single.

my idea:

  1. Get song duration in seconds = (1000=1sec. and a int64). if your number is 25.5 seconds long the time duration will be
    25500 (so divide it by 1000 to get the seconds (store that as a single)
  2. get your points in seconds
  3. divide your point by your duration and you get a VLC position based on seconds!

i.e. 13 seconds into a 25.5 minute songs would be
13 / 25.5 = 0.50980

I think that should work

1.player.play
2.player.pause
3.player.position = startpoint / (player.media.duration/1000)
4.player.play

what do you think?

It should work, it’s basically the same way the demo switches to and from full screen. The only thing I’d mention is that playback is asynchronous and runs on a separate thread, so don’t expect playback to have already started when the Play method returns. Read the VLCMediaPlayer.CurrentState property to determine what the player is doing right now (opening, buffering, playing, etc.)

hi Andrew,
just found this topic/conversation while searching for an easy way to create a movie player that can handle basic .mkv playback.
I cannot get the demo on https://github.com/charonn0/RB-libvlc to work under 2018r3. Is there something special i need to do to get it to work?
thanks,
Kristof

If you’ve got the most recent version of VLC then it might be their libraries that have changed. I’ve had some success using it with the last release, but their most recent update broke everything on the Mac. They changed how the paths were embedded into the libraries and nothing could be moved anymore. I was able to fix it using otool -L to see what they were doing and the using installNameTool to change the all the paths that reference @rpath to instead reference @executable_path. In order to get it to work I had to do that in all the VLC libraries and also in each and every one of the plugins as well. But upon doing that it did work. I don’t know if you’re on a mac or not or if this has anything to do with your problem. There may be a similar setting on windows that has changed as well. I worked for a while to actually recompile them with the proper load paths but that turned out to be an even worse pain. Ultimately I think I’ve given up on them anyway as I really needed them to load an RTSP stream and they just don’t do it reliably. They leak memory and eventually something hiccups and they can’t recover but hog 100% of a CPU just spinning on their buffer and never output another frame until you stop and restart the stream. I’ve been futzing with them on and off for years now as there is no other way to open an RTSP stream that I’m aware of but they just don’t work worth a darn. It’s very disappointing and maybe is how I”m doing it :wink: Though I’ve started from Christians examples so I can’t be too far off the mark.

Can you be more specific in how it’s not working?