4

I am trying to stream an online video using VLC media player. But the URL I'm receiving is random, so that URL needs to be linked to the VLC media player online stream. Is there any APIs that enables the random online video to be played ?

A small understanding of the project that I'm building...

  1. I have a device that will receive the URL from the server and will play it on a screen.

  2. Earlier I was playing it via a web browser. But this time I want it to implement it using a media player.Thus my question, is there any API for VLC media player that can be used to stream online videos?

*** BTW I'm using python to write my scripts.

2
  • @Shai you need image of what? I didn't get you Commented Jul 26, 2018 at 11:26
  • I posted this comment on another question, I have no idea how it ended up here o_O Commented Jul 26, 2018 at 12:07

2 Answers 2

5

As wizzwizz4 stated the vlc.py program is available @ https://wiki.videolan.org/Python_bindings along with example code for wxpython, pyQt and pyGtk
The documentation is here: https://www.olivieraubert.net/vlc/python-ctypes/doc/

Here is a rough bit of code, which runs from the command line, to give you a start

import requests import vlc import time import os #Test data a local file, a couple of radio stations and a video to cover all the bases urls = [ 'file:///home/rolf/Music/H5O.mp3', 'http://www.lounge-radio.com/listen128.m3u', 'http://network.absoluteradio.co.uk/core/audio/aacplus/live.pls?service=acbb', 'http://statslive.infomaniak.ch/playlist/energy90s/energy90s-high.mp3/playlist.pls', 'http://streaming.radio.rtl2.fr/rtl2-1-44-128', 'http://clips.vorwaerts-gmbh.de/VfE_html5.mp4' ] #Define playlist extensions playlists = set(['pls','m3u']) #Define vlc playing Status values playing = set([1,2,3,4]) Instance = vlc.Instance() # Loop over urls provided for url in urls: print ("\n\nLooking for:", url) # Grab file extension ext = (url.rpartition(".")[2])[:3] found = False # Test if url is a local file or remote if url[:4] == 'file': if os.path.isfile(url[7:]): found = True else: print ('Error: File ', url[7:], ' Not found') continue else: try: r = requests.get(url, stream=True) found = r.ok except ConnectionError as e: print('failed to get stream: {e}'.format(e=e)) continue if found: player = Instance.media_player_new() Media = Instance.media_new(url) Media_list = Instance.media_list_new([url]) Media.get_mrl() player.set_media(Media) # if url is a playlist load list_player else use player if ext in playlists: list_player = Instance.media_list_player_new() list_player.set_media_list(Media_list) if list_player.play() == -1: print ("\nError playing playlist") else: if player.play() == -1: print ("\nError playing Stream") #=========================================================# # #Use this code for 15 second samples print ('Sampling ', url, ' for 15 seconds') time.sleep(15) # #=========================================================# # #Use this code to play audio until it stops # print ('Playing ', url, ' until it stops') # time.sleep(5) #Give it time to get going # while True: # if ext in playlists: # state = list_player.get_state() # if state not in playing: # break # else: # state = player.get_state() # if state not in playing: # break #=========================================================# if ext in playlists: list_player.stop() else: player.stop() else: print ('\nError getting the audio') 
Sign up to request clarification or add additional context in comments.

Comments

1

If the URL is to the stream / video file, you can just open it directly in VLC like you would anything else. If it's to an HTML document, you'll need to extract the URL of the actual stream.

4 Comments

Yes .. the URL is to video file .. but I don't want to enter it manually .. as my device will keep on playing the video url's it receives from the server.
@askd VLC has a C API, and if you can't find a Python version you could make one using ctypes. Or you could use the command-line interface.
progur.com/2017/06/how-to-use-vlc-api-in-c.html I'll write you up a proper answer later. If I don't, feel free to remind me.
@askd wiki.videolan.org/Python_bindings will be better for you.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.