1

I use Http.fileSever() to upload a m3u8 file and some ts file to a server.Now,I request them and read them by ioutil.ReadAll.What should I do to play the m3u8 file. I tried to only request the m3u8 file,but I found I can not play it by ffplay. This is my request code

res, err := client.Get(url)
if err != nil {
    panic(err)
}
data, err := ioutil.ReadAll(res.Body)


defer res.Body.Close()
if err != nil {
    log.Fatal(err)
}
fmt.Println(string(data))

And this is what I got:

<pre>
<a href="origin.m3u8">origin.m3u8</a>
<a href="origin0.ts">origin0.ts</a>
<a href="origin1.ts">origin1.ts</a>
</pre>

What should I do to play the m3u8 file. Actually,I can play this m3u8 file,if I use ffplay to request the url directory like this:

    url := "http://192.168.0.110:8080/origin.m3u8"
    res, err := http.Get(url)
    if err != nil {
        panic(err)
    }
    defer res.Body.Close()
    data, err := ioutil.ReadAll(res.Body)
    c := exec.Command("cmd", "/c", "ffplay", url)
    if err := c.Run(); err != nil {
        fmt.Println("Error: ", err)
    }

But now,I`m try to implement a p2p system so that I only get data from client but not acrossing url

kou
  • 31
  • 3
  • What do you mean when saying „do play”? Do you mean "to play using the user's web browser performing the request"? – kostix Feb 14 '22 at 16:28
  • It takes a lot of work to play a stream. Fortunately libvlc has a binding for golang. You need to send the raw stream url to libvlc. https://github.com/adrg/libvlc-go – SeanTolstoyevski Feb 14 '22 at 22:19
  • Thank you for your advice,I have implement a system using such thing – kou Feb 26 '22 at 10:49

0 Answers0