title: Receiver app: HLS media fails to load with InvalidStateError
body: <p>Using the unmodified <a href="https://github.com/googlecast/cast-custom-receiver" rel="nofollow">cast-custom-receiver</a> example, I keep getting an uncaught InvalidStateError exception in the media_player.js library when attempting to load a HLS media stream.  My HLS stream has three variants.</p>
  
  <p>I don't believe this is a CORS issue as both my receiver app and video source are currently hosted together on S3 for testing purposes.</p>
  
  <p>For the record, I'm using a simple Chrome sender (a modified version of <a href="https://github.com/googlecast/CastHelloVideo-chrome" rel="nofollow">CastHelloVideo-chrome</a>) and have posted both <a href="http://stvdemo.s3.amazonaws.com/chromecast/sender.html" rel="nofollow">sender</a> and <a href="http://stvdemo.s3.amazonaws.com/chromecast/receiver.html" rel="nofollow">receiver</a> source publicly to Amazon S3 as well as the <a href="http://stvdemo.s3.amazonaws.com/chromecast/video/tv.main.hls-0.m3u8" rel="nofollow">HLS</a> stream I'm using for testing.</p>
  
  <p>Here is the receiver console output I see when the sender triggers the load media event:</p>
  
  <pre><code> [  0.919s] [cast.receiver.IpcChannel] Opening message bus websocket
   [  0.931s] [goog.net.WebSocket] Opening the WebSocket on ws://localhost:8008/v2/ipc
   [  0.970s] [goog.net.WebSocket] WebSocket opened on ws://localhost:8008/v2/ipc
   [  0.980s] [cast.receiver.IpcChannel] IpcChannel opened
   [  0.989s] [cast.receiver.CastMessageBus] Dispatching CastMessageBus message [urn:x-cast:com.google.cast.system, SystemSender]: {"type":"opened"}
   [  0.996s] [cast.receiver.CastReceiverManager] CastReceiverManager message received: [object Object]
   [  1.000s] [cast.receiver.CastReceiverManager] Underlying message bus is open
   [  1.003s] [cast.receiver.IpcChannel] IPC message sent: {"namespace":"urn:x-cast:com.google.cast.system","senderId":"SystemSender","data":"{\"type\":\"ready\",\"statusText\":\"Ready to play\",\"activeNamespaces\":[\"urn:x-cast:com.google.devrel.custom\",\"urn:x-cast:com.google.cast.media\"],\"version\":\"2.0.0\",\"messagesVersion\":\"1.0\"}"}
   [  1.015s] [cast.receiver.IpcChannel] IPC message sent: {"namespace":"urn:x-cast:com.google.cast.system","senderId":"SystemSender","data":"{\"type\":\"startheartbeat\",\"maxInactivity\":6000}"}
   [  1.025s] [cast.receiver.IpcChannel] Received message: {"data":"{\"applicationId\":\"CE156522\",\"applicationName\":\"Simple.TV Test\",\"launchingSenderId\":\"4:client-68913\",\"messagesVersion\":\"1.0\",\"sessionId\":\"A2A4AA7B-5CE5-9CA0-38CA-EEC77B84F4C6\",\"type\":\"ready\",\"version\":\"1.0\"}","namespace":"urn:x-cast:com.google.cast.system","senderId":"SystemSender"}
   [  1.028s] [cast.receiver.CastMessageBus] Dispatching CastMessageBus message [urn:x-cast:com.google.cast.system, SystemSender]: {"applicationId":"CE156522","applicationName":"Simple.TV Test","launchingSenderId":"4:client-68913","messagesVersion":"1.0","sessionId":"A2A4AA7B-5CE5-9CA0-38CA-EEC77B84F4C6","type":"ready","version":"1.0"}
   [  1.030s] [cast.receiver.CastReceiverManager] CastReceiverManager message received: [object Object]
   [  1.032s] [cast.receiver.CastReceiverManager] Dispatching CastReceiverManager system ready event [[object Object]]
  ### Cast Receiver Manager is READY: {"type":"ready","B":false,"defaultPrevented":false,"Qa":true,"data":{"id":"CE156522","name":"Simple.TV Test","sessionId":"A2A4AA7B-5CE5-9CA0-38CA-EEC77B84F4C6","namespaces":["urn:x-cast:com.google.devrel.custom","urn:x-cast:com.google.cast.media"],"launchingSenderId":"4:client-68913"}} 
   [  1.087s] [cast.receiver.IpcChannel] Received message: {"data":"{\"senderId\":\"4:client-68913\",\"type\":\"senderconnected\",\"userAgent\":\"\"}","namespace":"urn:x-cast:com.google.cast.system","senderId":"SystemSender"}
   [  1.089s] [cast.receiver.CastMessageBus] Dispatching CastMessageBus message [urn:x-cast:com.google.cast.system, SystemSender]: {"senderId":"4:client-68913","type":"senderconnected","userAgent":""}
   [  1.092s] [cast.receiver.CastReceiverManager] CastReceiverManager message received: [object Object]
   [  1.094s] [cast.receiver.CastReceiverManager] Dispatching CastReceiverManager sender connected event [4:client-68913]
   [  1.096s] [cast.receiver.CastMessageBus] Registering sender [urn:x-cast:com.google.devrel.custom, 4:client-68913]
   [  1.098s] [cast.receiver.CastMessageBus] Registering sender [urn:x-cast:com.google.cast.media, 4:client-68913]
  ### Cast Receiver Manager - Sender Connected : {"type":"senderconnected","B":false,"defaultPrevented":false,"Qa":true,"data":"4:client-68913"} 
   [ 21.168s] [cast.receiver.IpcChannel] Received message: {"data":"{\"type\":\"LOAD\",\"requestId\":90616069,\"sessionId\":\"A2A4AA7B-5CE5-9CA0-38CA-EEC77B84F4C6\",\"media\":{\"contentId\":\"http://stvdemo.s3.amazonaws.com/chromecast/video/tv.main.hls-0.m3u8\",\"streamType\":\"buffered\",\"contentType\":\"application/x-mpegURL\",\"metadata\":null,\"duration\":1800,\"customData\":null},\"autoplay\":false,\"currentTime\":0,\"customData\":null}","namespace":"urn:x-cast:com.google.cast.media","senderId":"4:client-68913"}
   [ 21.174s] [cast.receiver.CastMessageBus] Dispatching CastMessageBus message [urn:x-cast:com.google.cast.media, 4:client-68913]: {"type":"LOAD","requestId":90616069,"sessionId":"A2A4AA7B-5CE5-9CA0-38CA-EEC77B84F4C6","media":{"contentId":"http://stvdemo.s3.amazonaws.com/chromecast/video/tv.main.hls-0.m3u8","streamType":"buffered","contentType":"application/x-mpegURL","metadata":null,"duration":1800,"customData":null},"autoplay":false,"currentTime":0,"customData":null}
   [ 21.183s] [cast.receiver.MediaManager] MediaManager message received [4:client-68913] {"type":"LOAD","requestId":90616069,"sessionId":"A2A4AA7B-5CE5-9CA0-38CA-EEC77B84F4C6","media":{"contentId":"http://stvdemo.s3.amazonaws.com/chromecast/video/tv.main.hls-0.m3u8","streamType":"buffered","contentType":"application/x-mpegURL","metadata":null,"duration":1800,"customData":null},"autoplay":false,"currentTime":0,"customData":null}
   [ 21.187s] [cast.receiver.MediaManager] Dispatching MediaManager load event
  ### Media Manager - LOAD: {"type":"load","B":false,"defaultPrevented":false,"Qa":true,"data":{"requestId":90616069,"sessionId":"A2A4AA7B-5CE5-9CA0-38CA-EEC77B84F4C6","media":{"contentId":"http://stvdemo.s3.amazonaws.com/chromecast/video/tv.main.hls-0.m3u8","streamType":"buffered","contentType":"application/x-mpegURL","metadata":null,"duration":1800,"customData":null},"autoplay":false,"currentTime":0,"customData":null},"senderId":"4:client-68913"}
  ### Media Protocol Identified as m3u8
  ######### MEDIA ELEMENT LOAD START
  Uncaught InvalidStateError: An attempt was made to use an object that is not, or is no longer, usable. media_player.js:101
  ######### MEDIA ELEMENT ERROR [object Event]
   [ 22.299s] [cast.receiver.MediaManager] Load metadata error
  ### Media Manager - LOAD METADATA ERROR: {"senderId":"4:client-68913","message":{"requestId":90616069,"sessionId":"A2A4AA7B-5CE5-9CA0-38CA-EEC77B84F4C6","media":{"contentId":"http://stvdemo.s3.amazonaws.com/chromecast/video/tv.main.hls-0.m3u8","streamType":"buffered","contentType":"application/x-mpegURL","metadata":null,"duration":1800,"customData":null},"autoplay":false,"currentTime":0,"customData":null}} 
   [ 22.310s] [cast.receiver.MediaManager] Resetting media element
   [ 22.319s] [cast.receiver.MediaManager] Sending error message to 4:client-68913
   [ 22.324s] [cast.receiver.IpcChannel] IPC message sent: {"namespace":"urn:x-cast:com.google.cast.media","senderId":"4:client-68913","data":"{\"requestId\":90616069,\"type\":\"LOAD_FAILED\"}"}
  </code></pre>