gstplaystream.lua 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. #! /usr/bin/env lua
  2. --
  3. -- Sample GStreamer application, port of public Vala GStreamer Audio
  4. -- Stream Example (http://live.gnome.org/Vala/GStreamerSample)
  5. --
  6. local lgi = require 'lgi'
  7. local GLib = lgi.GLib
  8. local Gst = lgi.Gst
  9. local main_loop = GLib.MainLoop()
  10. local function bus_callback(bus, message)
  11. if message.type.ERROR then
  12. print('Error:', message:parse_error().message)
  13. main_loop:quit()
  14. elseif message.type.EOS then
  15. print 'end of stream'
  16. main_loop:quit()
  17. elseif message.type.STATE_CHANGED then
  18. local old, new, pending = message:parse_state_changed()
  19. print(string.format('state changed: %s->%s:%s', old, new, pending))
  20. elseif message.type.TAG then
  21. message:parse_tag():foreach(
  22. function(list, tag)
  23. print(('tag: %s = %s'):format(tag, tostring(list:get(tag))))
  24. end)
  25. end
  26. return true
  27. end
  28. local play = Gst.ElementFactory.make('playbin', 'play')
  29. play.uri = 'http://streamer-dtc-aa02.somafm.com:80/stream/1018'
  30. --play.uri = 'http://www.cybertechmedia.com/samples/raycharles.mov'
  31. play.bus:add_watch(GLib.PRIORITY_DEFAULT, bus_callback)
  32. play.state = 'PLAYING'
  33. -- Run the loop.
  34. main_loop:run()
  35. play.state = 'NULL'