On this page:
media-file-server?
start-media-file-server
media-file-server-url
media-file-server-publish!
media-file-server-unpublish!
media-file-server-didl-lite
media-file-server-stop!
6.1 Playing local files
9.3

6 Publishing Media Files🔗ℹ

 (require racket-upnp/media-file-server)
  package: racket-upnp

This module publishes local files through a small Racket web server. The underlying Racket file dispatcher streams files and supports both HEAD requests and HTTP byte ranges. Byte ranges are important for media-renderer probing and seeking.

At info log level, each published transfer reports its start and completion or interruption, including client address, HTTP method, requested range and elapsed time. No publication lock is held while the response is being streamed.

procedure

(media-file-server? value) → boolean?

  value : any/c
Returns #t when value is a media file server.

procedure

(start-media-file-server url 
  [#:listen-ip listen-ip]) 
 → media-file-server?
  url : string?
  listen-ip : (or/c #f string?) = #f
Starts a server for the HTTP origin and path prefix in url. The URL must be an absolute http:// URL. A trailing slash is added when needed.

When listen-ip is #f, the server listens on all local interfaces. Supply a local address, such as 10.7.3.118, to restrict the listener to that interface.

procedure

(media-file-server-url server) → string?

  server : media-file-server?
Returns the normalized base URL of server.

procedure

(media-file-server-publish! server    
  file    
  url    
  [#:mime-type mime-type]) → string?
  server : media-file-server?
  file : path-string?
  url : string?
  mime-type : (or/c #f bytes? string?) = #f
Publishes file at url and returns the absolute URL.

The URL may be relative to the server URL:

(define uri
  (media-file-server-publish!
   files
   "C:/muziek/test.flac"
   "test.flac"))

It may also be the complete URL, provided that its origin and path prefix match the server:

(media-file-server-publish!
 files
 "C:/muziek/test.flac"
 "http://10.7.3.118:8080/media/test.flac")

The MIME type is inferred for common audio, video, and image extensions. Use #:mime-type to override it.

procedure

(media-file-server-unpublish! server url) → void?

  server : media-file-server?
  url : string?
Removes the URL mapping. Requests that are already in progress may still finish.

procedure

(media-file-server-didl-lite server    
  url    
  [#:title title    
  #:artist artist    
  #:album album    
  #:genre genre    
  #:year year    
  #:track track    
  #:duration duration    
  #:id id    
  #:parent-id parent-id]) → string?
  server : media-file-server?
  url : string?
  title : (or/c #f string?) = #f
  artist : (or/c #f string?) = #f
  album : (or/c #f string?) = #f
  genre : (or/c #f string?) = #f
  year : (or/c #f exact-nonnegative-integer?) = #f
  track : (or/c #f exact-nonnegative-integer?) = #f
  duration : (or/c #f nonnegative-real?) = #f
  id : string? = "0"
  parent-id : string? = "0"
Returns DIDL-Lite metadata for a URL previously installed with media-file-server-publish!. The MIME type, file size, and DLNA.ORG_OP=01 byte-range capability are taken from the actual publication. The file name is used as the title when title is #f.

Pass the result as #:metadata or #:next-metadata to the media-renderer functions. Supplying the duration is recommended because some renderers use it when deciding whether time seeking is available.

procedure

(media-file-server-stop! server) → void?

  server : media-file-server?
Stops the web server. Repeated calls have no effect.

6.1 Playing local files🔗ℹ

(define files
  (start-media-file-server
   "http://10.7.3.118:8080/media/"
   #:listen-ip "10.7.3.118"))
 
(define first-uri
  (media-file-server-publish!
   files
   "C:/muziek/first.flac"
   "first.flac"))
 
(define second-uri
  (media-file-server-publish!
   files
   "C:/muziek/second.flac"
   "second.flac"))
 
(define first-metadata
  (media-file-server-didl-lite
   files
   first-uri
   #:title "First track"
   #:duration 639))
 
(define second-metadata
  (media-file-server-didl-lite
   files
   second-uri
   #:title "Second track"
   #:duration 242))
 
(media-renderer-play-uri!
 renderer
 first-uri
 #:metadata first-metadata
 #:next-uri second-uri
 #:next-metadata second-metadata)

Keep the URLs published until the renderer has finished reading them.