playlist.go 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. /*
  2. * DudelDu
  3. *
  4. * Copyright 2016 Matthias Ladkau. All rights reserved.
  5. *
  6. * This Source Code Form is subject to the terms of the MIT
  7. * License, If a copy of the MIT License was not distributed with this
  8. * file, You can obtain one at https://opensource.org/licenses/MIT.
  9. */
  10. package dudeldu
  11. import "errors"
  12. /*
  13. FrameSize is the suggested size of a frame which should be send to the client
  14. at a time.
  15. The absolute theoretical maximum frame size for a MPEG audio is 2881 bytes:
  16. MPEG 2.5 Layer II, 8000 Hz @ 160 kbps, with a padding slot.
  17. Theoretical frame sizes for Layer III range from 24 to 1441 bytes
  18. there is a "soft" limit imposed by the standard of 960 bytes.
  19. see: http://www.mars.org/pipermail/mad-dev/2002-January/000425.html
  20. */
  21. const FrameSize = 3000
  22. /*
  23. ErrPlaylistEnd is a special error code which signals that the end of the playlist has been reached
  24. */
  25. var ErrPlaylistEnd = errors.New("End of playlist")
  26. /*
  27. Playlist is an object which provides a request handler with a
  28. constant stream of bytes and meta information about the current playing title.
  29. */
  30. type Playlist interface {
  31. /*
  32. Name is the name of the playlist.
  33. */
  34. Name() string
  35. /*
  36. ContentType returns the content type of this playlist e.g. audio/mpeg.
  37. */
  38. ContentType() string
  39. /*
  40. Artist returns the artist which is currently playing.
  41. */
  42. Artist() string
  43. /*
  44. Title returns the title which is currently playing.
  45. */
  46. Title() string
  47. /*
  48. Frame returns the current audio frame which is playing.
  49. */
  50. Frame() ([]byte, error)
  51. /*
  52. ReleaseFrame releases a frame which has been written to the client.
  53. */
  54. ReleaseFrame([]byte)
  55. /*
  56. Finished returns if the playlist has finished playing.
  57. */
  58. Finished() bool
  59. /*
  60. Close any open files by this playlist and reset the current pointer. After this
  61. call the playlist can be played again unless an error is returned.
  62. */
  63. Close() error
  64. }
  65. /*
  66. PlaylistFactory produces a Playlist for a given path.
  67. */
  68. type PlaylistFactory interface {
  69. /*
  70. Playlist returns a playlist for a given path.
  71. */
  72. Playlist(path string, shuffle bool) Playlist
  73. }