Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

[RELEASED] VLC Player for Unity (New: Youtube Streaming!)

Discussion in 'Assets and Asset Store' started by chassets, Feb 21, 2016.

  1. chassets

    chassets

    Joined:
    Nov 27, 2013
    Posts:
    310
    What exactly do you mean by live video? Every video that VLC supports can be played. If you mean youtube livestreams: as it says in the asset store description, you should test the links with a installed VLC before, since google sometimes changes something on youtube, then you will have to wait for a newer VLC version that can play these videos again. You can try to update the used vlc version in your streaming assets folder with a new VLC 3.0 build though and see if that helps!

    Hope that helps, best regards
     
  2. rodellison

    rodellison

    Joined:
    Oct 3, 2014
    Posts:
    24
    Hello all, was hoping to ask a question related to using VLCLan for displaying 360+3D video (example) in my Unity Rift VR project. I have this essentially working but am unsure if I'm doing it correctly.
    Essentially, I have a blender model with two spheres (sphereL and sphereR), using the same material, with each sphere's UV mapped to the respective top and bottom half of the video.
    I've brought the model into Unity, and have placed the VLCLan scripts (PlayVLC and VLCtoGSTextureStream) on each sphere. I have my Oculus separate L/R eye cameras culling the left and right sphere as appropriate. When I play/stream the video, it renders correctly (top half on left eye, bottom half on right eye) ...But it starts two VLC.exe instances - so I'm curious its streaming the duplicate content for each eye and I'm losing performance in some way.
    Is this the right way to do this? do the scripts need to be on both spheres (with play started simultaneously) and two VLC instances running?

    thanks!
     
  3. ForceX

    ForceX

    Joined:
    Jun 22, 2010
    Posts:
    1,102
    I know this packages focus is on video playback but how is it with audio formats such as FLAC, M4A, or multi channel AAC; are any of these supported? I'm interested in creating a music library player that can detect & load external FLAC & M4A files & read the tag metadata.
     
  4. chassets

    chassets

    Joined:
    Nov 27, 2013
    Posts:
    310
    Hi! The asset can play everything VLC supports, not only video files, but also audio files. In addition you can also play a video, but discard the video info and just play the audio - also works with youtube videos as audio only.
     
  5. chassets

    chassets

    Joined:
    Nov 27, 2013
    Posts:
    310
    Hi Rod,
    sorry for the late reply. The scripts do not need to be on both spheres, they just need to have the same video material. In the texture streaming script the video texture / material is set for the mesh renderer of the object that has the script on - there you could assign it to both spheres.

    Hope it's clear what I mean, if you need more help just drop me an email. (Don't always get a mail from unity if there is a new post here)
     
  6. ForceX

    ForceX

    Joined:
    Jun 22, 2010
    Posts:
    1,102
    Purchased and it's working great, i'm already building a library/playlist manager to use with this :)
     
  7. chassets

    chassets

    Joined:
    Nov 27, 2013
    Posts:
    310
    Great! I didn't really really "design" it to be used as a audioplayer, so in case you run in any troubles there feel free to contact me via mail, maybe I'm able to help.
     
  8. ForceX

    ForceX

    Joined:
    Jun 22, 2010
    Posts:
    1,102
    The only question i have ATM is when a file is playing what do I need to do to play a new file of my choosing.

    Example:
    I have a list of 5 videos that i have displayed as buttons in a UI list. Video 1 is playing but i want to switch to video 4 by clicking on its button to load the video.

    My first reaction was to create a script that sets VideoPaths[0] to the file i want to play then call the Play() function. This works but only the first time. After a video is playing I can set the new file plath to VideoPaths[0] but i am unable to get the file to start playing. I have tried calling StopVideo(); & QuitAllVideos(); prior to calling Play() but no luck.

    The method above does work when "Skip Video With Any Key" is enabled however Pause/Resume will not work.

    If this is possible then I would like to create a custom function that will take in a string / file path and play that file. PlayCustom("\file Path\file.mp4");

    I know i need to do something to bring VLC back to a fresh condition ready to accept a file to play, i'm just not sure what that something is.

    [Edit : Basic example of functionality I am going for]

    Code (csharp):
    1.  
    2.         string[] fileList;
    3.  
    4.         PlayVLC.StopVideo();
    5.  
    6.         for (int i = 0; i < fileList.Length; i++) {
    7.             if (Button Is Pressed) {
    8.                 PlayVLC.VideoPaths[0] = fileList[i];
    9.             }
    10.         }
    11.  
    12.         PlayVLC.Play();
    13.  
     
    Last edited: May 15, 2017
  9. chassets

    chassets

    Joined:
    Nov 27, 2013
    Posts:
    310
    Jup, you are doing this right, but you need to give the VLC app a very short amount of time between stopping and playing again. Just tested this and it works as expected. Hope this helps, sorry for the inconvenience. I will add functions to play a specific file to PlayVLC.cs for the next update, so this is easier.

    Edit: maybe you could also be interested in using the existing playlist functionality along with the control request functions (see readme), but I guess this might not be flexible enough for what you are developing.

    Code (CSharp):
    1. public void SetVLCStreamingURL(string url)
    2.     {
    3.         PlayVLC.StopVideo();
    4.         PlayVLC.VideoPaths[0] = url;
    5.         Invoke("StartPlayback", 0.1f);      
    6.     }
    7.  
    8.     private void StartPlayback(){
    9.         PlayVLC.Play();
    10.     }
     
    Last edited: May 15, 2017
  10. ForceX

    ForceX

    Joined:
    Jun 22, 2010
    Posts:
    1,102
    Perfect, I just needed to give it some time :)

    I love this asset I've gotten all the functionality up and running quite easily, even have time scrubbing with a slider bar. This is awesome I can finally make a media player front end that I like. Only thing left is reading ID tags for metadata.
     
  11. ForceX

    ForceX

    Joined:
    Jun 22, 2010
    Posts:
    1,102
    I forgot to mention that the CR_GetCurrentTime(), CR_GetVideoDuration(), & CR_GetCurrentVolumeLevel() were all set to return _VideoInfo_CurrentTimeSeconds;

    I made the changes to reflect their respected return paths.

    Code (csharp):
    1.  
    2.     /// <summary>
    3.     /// Get current time in seconds.
    4.     /// </summary>
    5.     /// <returns>current time in seconds ,returns -1 if not playing</returns>
    6.     public int CR_GetCurrentTime() {
    7.         if (IsPlaying) {
    8.             return _VideoInfo_CurrentTimeSeconds;
    9.         }else {
    10.             return -1;
    11.         }
    12.     }
    13.     /// <summary>
    14.     /// Get length of the current video in seconds.
    15.     /// </summary>
    16.     /// <returns> video length in seconds, returns -1 if not playing</returns>
    17.     public int CR_GetVideoDuration(){
    18.       if (IsPlaying){
    19.             return _VideoInfo_DurationSeconds;
    20.         }else{
    21.             return -1;
    22.         }
    23.     }
    24.     /// <summary>
    25.     /// Get current volume level
    26.     /// </summary>
    27.     /// <returns>current volume level, returns -1 if not playing</returns>
    28.     public int CR_GetCurrentVolumeLevel() {
    29.         if (IsPlaying){
    30.             return _VideoInfo_CurrentVolume;
    31.         }else{
    32.             return -1;
    33.         }
    34.     }
    35.  




    Edit : Sadly file duration only works on Video files ATM.

    .
     
  12. ForceX

    ForceX

    Joined:
    Jun 22, 2010
    Posts:
    1,102
    One last strange issue _VideoInfo_DurationSeconds & _VideoInfo_CurrentTimeSeconds work on FLAC, m4a but only if a video file was played first.

    If Video File Plays First :
    _VideoInfo_DurationSeconds & _VideoInfo_CurrentTimeSeconds report correct information for the video file.

    If Video File Plays First Then Play Audio File :
    _VideoInfo_DurationSeconds & _VideoInfo_CurrentTimeSeconds report correct information for both files.


    If Audio File Plays First :
    _VideoInfo_DurationSeconds & _VideoInfo_CurrentTimeSeconds incorrectly reports 0 for the time. Until a video file plays.


    I'm currently looking into the VLC /requests/status.xml & how to extract more data
     
  13. chassets

    chassets

    Joined:
    Nov 27, 2013
    Posts:
    310
    interesting - sounds like a VLC bug, you could also try to replace the used VLC version with a newer one (or even the new 3.0.0 preview builds, they work pretty well), you can just replace the VLC folder in streaming assets. But I found different issues with most of the versions I tried, however.

    Also thank you very much for pointing out that the return values were wrong, my bad. Must have mixed up something when submitting the last version. Will fix this and upload a new version with a couple of improvements soon.
     
    Last edited: May 16, 2017
  14. FLYUPAV

    FLYUPAV

    Joined:
    Aug 1, 2013
    Posts:
    34
    Hi
    I want to play different movies form StreamingAssets using different buttons. What do you suggest to do? I was failed to Hide/ Unhide different panels by buttons? Why the movies still running in background after hiding its assigned UI panel?
     
  15. chassets

    chassets

    Joined:
    Nov 27, 2013
    Posts:
    310
    Hi. Just take a look at the demoscenes and readme (there is a explanation of all methods available)- the UI images are just for placement, since the videos are rendered directly to screen (fastest playback). To play a specific video, create a PlayVLC instance and start it with a button calling the Play() function. To stop displaying the videos and hiding them from display, call the StopVideo() function.

    If you absolutely need to stop displaying the video while keeping it playing, you can use the texture2d beta extension and play directly inside the texture2d of an UI element, or you can move the UI image to a location where it is not visible.
     
    Last edited: May 16, 2017
  16. ForceX

    ForceX

    Joined:
    Jun 22, 2010
    Posts:
    1,102
    Will do I'll try it tonight after work. I finally figured out how to access the VLC status.xml via web browser; the odd thing is it shows the correct data. Track length, current time, meta data is all there when looking at it through the web browser.

    Edit :
    If I remember correctly I think I tried loading a video with Audio only enabled and it to would not report any time data as well. I looked but didn't see any condition that prevents data if no video is running.
     
    Last edited: May 16, 2017
  17. ForceX

    ForceX

    Joined:
    Jun 22, 2010
    Posts:
    1,102
    I tried one of the nightly builds but just got the same result. For now i'll just hack it. I created 2 second blank video file that loads and unloads at the beginning. It's just odd, the data is there i'm not sure why it's not reading it.
     

    Attached Files:

  18. WenchaoDeng

    WenchaoDeng

    Joined:
    May 16, 2017
    Posts:
    3
    Hi,
    I download TextureStreamDemo and then double-click to run TextureStream.exe, but the video doesn't work. are there some steps misssing?
    BTW, my VLC version is vlc-2.2.4-win32
     
  19. WenchaoDeng

    WenchaoDeng

    Joined:
    May 16, 2017
    Posts:
    3
    Another question.
    My camera's RTSP stream works well on VLC player, is it sure to work well on the texture plugin?
    All the best and looking forward to purchase.
     
  20. fcglobalmedia

    fcglobalmedia

    Joined:
    May 22, 2017
    Posts:
    9
    Hi,
    i'm a newbie but i purchesed the VLC Media Player for make a video player application and is working great.
    Sorry but how can i detect when a video finishes? At the end of the video i want to came back to the menu scene.
    Thanks!
     
  21. chassets

    chassets

    Joined:
    Nov 27, 2013
    Posts:
    310
    Hey sorry for the late reply! It's easier to reach me on the support mail / form on my website chassets.wordpress.com. Have you checked if it is blocked by your firewall? Since the video loaded is a youtube link, this is most probably the case.
     
    Last edited: Dec 8, 2017
  22. chassets

    chassets

    Joined:
    Nov 27, 2013
    Posts:
    310
    Great, glad it is useful to you.

    Could you contact me on my support mail? Then I can send you the newest not released version, which brings a unity event for this - so it is pretty easy to call or do something once a video finishes.
     
    Last edited: Dec 8, 2017
  23. WenchaoDeng

    WenchaoDeng

    Joined:
    May 16, 2017
    Posts:
    3
    thanks for reply. I try
    and it works well in browser.
    actually,I want to check if my camera rtsp stream works well in TextureStreamDemo, is it prossible to do that?
     
  24. chassets

    chassets

    Joined:
    Nov 27, 2013
    Posts:
    310
    I think you misunderstood. The demo app needs firewall access to access the web to play the youtube video (it should pop up on windows asking you for permission, as with any other program that wants to access the internet for the first time), did nothing ask you for permission?

    You can email me the link to your rstp stream, then I'll test it for you.

    Best regards
     
  25. ForceX

    ForceX

    Joined:
    Jun 22, 2010
    Posts:
    1,102
    YES!! I finally figured out why time reporting was not working when an audio file was played first.

    Code (csharp):
    1.  
    2.     private void UpdateVideoInformation() {
    3.         if (IsPlaying && VLCWindowIsRendered()){
    4.  
    When an audio source is played first there is not VLC Window so i changed it to this.

    Code (csharp):
    1.  
    2.     private void UpdateVideoInformation() {
    3.         if (IsPlaying){
    4.  
    No more hacking it!! :))
     
  26. chassets

    chassets

    Joined:
    Nov 27, 2013
    Posts:
    310
    Thanks for pointing this out, totally forgot about it. But I guess I put it there for a reason, hope everything works as expected - since this basically waits until VLC is up and running (for video playback).

    Thanks again ! Best regards!
     
  27. ForceX

    ForceX

    Joined:
    Jun 22, 2010
    Posts:
    1,102
    As far as I can tell everything is working great, both in editor and as a runtime build.

    The only thing I have left to do is create the UI for a first time use setup wizard that allows the user to select a music directory. After that I should be ready so start sharing compiled builds.

    Thanks for your support I couldn't have done this with out VLC Player for Unity :)
     
  28. chassets

    chassets

    Joined:
    Nov 27, 2013
    Posts:
    310
    That's awesome. Glad you like it, I'm happy that it is useful to you. If you have the time, it would be super awesome if you'd consider rating or reviewing the asset :) Thanks a lot if you decide to do so, but if you don't have time for that it's also totally fine :)

    I'll probably remove the check if the VLC video output is rendered then, but I'll test it with a couple of videos / streams first. Thank you again for telling me.
     
  29. ForceX

    ForceX

    Joined:
    Jun 22, 2010
    Posts:
    1,102
    Review left :)

    I (haven't / forgot) to test any video files only audio formats. I'll try a few videos out tonight after work.

    Just thinking, and I'm not sure, but you would think because the script is querying VLC for playback statistics via the xml file, the video window should be of no consequence. Unless the xml is only generated after the video window or something strange like that. I'll do some more testing and let you know.
     
  30. Ben-Howard

    Ben-Howard

    Joined:
    Jul 21, 2014
    Posts:
    23
    Hello Dev,

    Looks like a great product - and a very competitive price compared to AVPro by Renderheads :O

    Considering a purchase and was hoping you could tell me if this asset would support streaming to a basic auth url - would need the ability to insert headers into the url. If this IS the case, I will purchase immediately. Thanks!!
     
  31. chassets

    chassets

    Joined:
    Nov 27, 2013
    Posts:
    310
    Hi! Sorry for the late reply, I'm easier to reach by mail :)

    You can test this like this: open a recent VLC version installed on your PC, copy your link with the authentification and and video URL and paste it with CTRL-V while having the VLC window active - then click on play. When it plays it will also play with the plugin.

    I believe I tested a link with auth a while back if I'm not mistaken, I believe it worked. The internet says it should work after a quick googling around.

    Best regards
     
  32. sgower

    sgower

    Joined:
    Mar 9, 2015
    Posts:
    316
    Hi, I'd like to include some youtube tutorials in my game. It's a VR game, so I need the videos to display on a plane. Will this Asset work? This looks interesting, but would this only work for users who separately download VLC? Or can I (legally) bundle everything that is needed in my game? I haven't used VLC, but it looks like a free and open source video player, although I'm not sure about if redistribution is possible or not. I apologize if this has been answered in a previous message, but I scrolled around the thread a bit and didn't see an answer.
     
  33. chassets

    chassets

    Joined:
    Nov 27, 2013
    Posts:
    310
    Hi! You can use the texture2d extension for playing youtube videos on a mesh - the "normal mode" is for 2d videos only. You can find a demo on the website which streams a youtube link on a 3d quad in the scene (link is in asset store description as well as all infos, requirements/restictions to the free texture2d extension and everything else)

    VLC is included in the streaming assets folder of the build, but not compiled into your build (that is the special thing about this plugin)- so according to the VLC FAQ you can freely redistribute VLC this way without the need to ask for permission or the need to use the same gnu licenses as VLC.

    Hope this helps,
    best regards
     
  34. PhilipKeenanPhilips

    PhilipKeenanPhilips

    Joined:
    Jul 13, 2017
    Posts:
    2
    Hello, this might be a bit out there, but would this display an rtsp stream from VLC on a PC to a Microsoft Hololens? I'm looking to put a live stream from a capture card on the PC to a UI window in our Unity App on the Hololens. The hololens currently uses the windows store build option with x86 architecture.
     
  35. chassets

    chassets

    Joined:
    Nov 27, 2013
    Posts:
    310
    Hi!
    I don't think that it will work for hololens, but I still haven't had a chance to get my hands on one. Sorry.
     
  36. xueluofeng

    xueluofeng

    Joined:
    Sep 4, 2017
    Posts:
    2
    I'm doing htc vive unity development, but i have encountered a problem where i need to add a panorama video at the beginning of the project but i do not know what to do and hope to get your help thanks
     
  37. chassets

    chassets

    Joined:
    Nov 27, 2013
    Posts:
    310
    Hi! For this you'd use the texture2d beta, which is not part of the asset store package. You can find the download link and howto in either the asset store description or the readme. A demoscene is included which renders video on a plane. If you change the plane to a sphere, you have 360°.
     
  38. xueluofeng

    xueluofeng

    Joined:
    Sep 4, 2017
    Posts:
    2
    Hi, thank you very much for your help, but I found in the asset store is a 2015 old version, did not find the demo version of the demo,This is very frustrating
     
  39. chassets

    chassets

    Joined:
    Nov 27, 2013
    Posts:
    310
    I do not understand what you are talking about - the version in the asset store is from 2017, and everything is described in the readme, as I said. If you need further help, contact me via mail and please include your invoice number.
     
  40. NovaDynamics

    NovaDynamics

    Joined:
    Sep 6, 2017
    Posts:
    25
    I'm having an issue I was hoping I could get some help on. I am attempting to receive two separate video streams via rtp. I set up two objects, one for each stream and attached the PlayVLC script attached to each one. I am also using the VLC to GS texture script on there. It works, but intermittently. Sometimes one stream will come up, and some times the other. Occasionally both will work at the same time. I opened task managed and noticed that when both streams are working, I would have two instances of vlc in the task manager, and when one stream was working I would only have one in the task manager. Do you know why this is happening?
     
  41. NovaDynamics

    NovaDynamics

    Joined:
    Sep 6, 2017
    Posts:
    25
    Separate problem: I have an object with the PlayVLC and texture script on it, but ever since I added a gui layer, it won't print to the object's texture. Only on the gui layer. Is there a way to disable the output on the gui layer? Or maybe to let it print to the gui and the texture?

    Thanks!
     
  42. chassets

    chassets

    Joined:
    Nov 27, 2013
    Posts:
    310
    You have to assign different ports to the scripts, see the 2 public variables in both scripts. Change them to something else for your second video.

    For your second question: that shouldn't happen, also doesn't happen im the demo scene (there the buttons are GUI).

    Do you have a UI component on the gameobject with the mesh renderer? If it is on a mesh renderer, it will render to the materials texture, but if a UI image is on the object, it will render to the UI image.
     
  43. NovaDynamics

    NovaDynamics

    Joined:
    Sep 6, 2017
    Posts:
    25
    Yes, I made sure that the ports were set different on each object. Both the control ports and stream ports. Its as if VLC is crashing on startup half the time. I tried downgrading VLC versions and using a installation outside of Assets, with no luck.

    As for the second problem, I figured it out. Instead of calling "PlayVLC.Play()" I needed to be calling "VLCtoGSTextureStream.TextureStreamPlay()"
     
    Last edited: Sep 7, 2017
  44. chassets

    chassets

    Joined:
    Nov 27, 2013
    Posts:
    310
    Yes, when using the seperate texture2d extension, you need to use its functions. Calling PlayVLC.cs functions is for the "regular" version that is available in the asset store. Maybe this was also the issue with the 2 video simultaneous playback?
     
  45. NovaDynamics

    NovaDynamics

    Joined:
    Sep 6, 2017
    Posts:
    25
    I don't think so as I am only calling one function. (the TextureStreamPlay function)

    I also noticed the it will occasionally leave the VLC processes going in the background even after the unity application is closed.
     
  46. NovaDynamics

    NovaDynamics

    Joined:
    Sep 6, 2017
    Posts:
    25
    Right. So I did some more troubleshooting and found that when the problem occurs, this line here is fired:

    if (_vlc.HasExited && !_thisVlcProcessWasEnded) {

    I believe this means that VLC is crashing on startup, but I could be wrong.
     
  47. NovaDynamics

    NovaDynamics

    Joined:
    Sep 6, 2017
    Posts:
    25
    Allright. I can make it happen every time if I up the resolution of the RTP stream. VLC will start, wait about a second, then silently close. This doesn't seem to happen if I am either not using the VLCtoText2d, or am using a lower quality stream. Youtube seems to work fine though.
     
  48. chassets

    chassets

    Joined:
    Nov 27, 2013
    Posts:
    310
    Hi! Sounds like VLC crashes in the background in your constellation (with the extension) - could be bug with highter resolutions or bitrates. You could try to replace the used VLC version in streaming assets and see if that helps.

    Sorry for the inconvenience, but as it says on the asset store description, the texture2d beta is seperate from the plugin - I just created it fbecause there was a demand for it, but not everything is guaranteed to work and since unity upgraded their video capabilities with 5.6, I haven't really improved it further.

    Instead, I'd like to integrate it with unitys new player, so that you can use this to play more formats or streams with it - but I just hadn't had the time yet, too much to do at work these days...

    PS: Maybe you could use something other than RTP?
     
  49. 19970322

    19970322

    Joined:
    Jun 20, 2016
    Posts:
    1
    Hi! I have a question about the RTSP streaming.I cahage the buffer on vlc.But it not working.
     
  50. chassets

    chassets

    Joined:
    Nov 27, 2013
    Posts:
    310