You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
So I'm implementing an API that receives an URL in JSON format from an HTTP request, and plays the video using VLC. However, the player never starts, when I use the -vvv flag VLC seems to be alive but not reproducing anything. FYI, I'm currently running this on Manjaro, but plan to implement it on a Rasp Berry Pi running on Raspbian. Thanks in advance.
Here's what I have so far:
my handler:
func (v*VlcManager) playStream(c*gin.Context) {
v.Log.Debug("playing stream")
Player=nil// Get the infor from streamURL jsonvarstreamURLStreamURLerr:=c.BindJSON(&streamURL)
iferr!=nil {
v.Log.Warn("failed to bind json", zap.Error(err))
c.JSON(http.StatusInternalServerError, err)
return
}
url:=string(streamURL.URL)
fmt.Println("url: ", url)
ifv.ConfigService!=nil {
stream, err:=v.ConfigService.GetStreamConfig(c.Request.Context(), url)
iferr==nil&&stream.Secret!="" {
// the token is everything after the base URLtoken, err:=v.generateToken(stream)
iferr!=nil {
v.Log.Error("error generating secure token: %s", zap.Error(err))
c.JSON(http.StatusInternalServerError, err)
return
}
v.Log.Info("generated secure token", zap.String("token", token))
url+=token
}
}
Player, err=helpers.SwitchStream(Player, url)
iferr!=nil {
v.Log.Warn("failed to switch stream", zap.Error(err))
c.JSON(http.StatusInternalServerError, err)
return
}
c.JSON(http.StatusOK, "stream playing")
}
the actual command:
funcSwitchStream(player*vlc.Player, streamstring) (*vlc.Player, error) {
// Initialize libVLC. Additional command line arguments can be passed in// to the libVLC by specifying them in the Init function.iferr:=vlc.Init("-vvv"); err!=nil {
log.Fatal(err)
returnnil, err
}
defervlc.Release()
// Create a new player.player, err:=vlc.NewPlayer()
iferr!=nil {
log.Fatal(err)
returnnil, err
}
deferfunc() {
player.Stop()
player.Release()
}()
media, err:=player.LoadMediaFromURL(stream)
iferr!=nil {
log.Fatal(err)
log.Printf("error loading media: %s", err)
returnnil, err
}
defermedia.Release()
manager, err:=player.EventManager()
iferr!=nil {
log.Fatal(err)
}
quit:=make(chanstruct{})
eventCallback:=func(event vlc.Event, userDatainterface{}) {
close(quit)
}
eventID, err:=manager.Attach(vlc.MediaPlayerEndReached, eventCallback, nil)
iferr!=nil {
log.Fatal(err)
}
defermanager.Detach(eventID)
iferr!=nil {
log.Fatal(err)
}
defermanager.Detach(eventID)
//Start playing the media.iferr=player.Play(); err!=nil {
log.Fatal(err)
log.Printf("error playing media: %s", err)
returnnil, err
}
<-quitreturnplayer, nil
}
The text was updated successfully, but these errors were encountered:
At a first glance, one thing you can try is to initialize libVLC just once, preferably on the main thread (somewhere at the beginning of your main function perhaps) instead of doing so per request.
Can you please provide a minimal sample which I can run and test the issue?
So I'm implementing an API that receives an URL in JSON format from an HTTP request, and plays the video using VLC. However, the player never starts, when I use the
-vvv
flag VLC seems to be alive but not reproducing anything. FYI, I'm currently running this on Manjaro, but plan to implement it on a Rasp Berry Pi running on Raspbian. Thanks in advance.Here's what I have so far:
my handler:
the actual command:
The text was updated successfully, but these errors were encountered: