Handling Chromecast load errors in web-based sender

Brad

The documentation for a web-based Chromecast sender says that castSession.loadMedia() returns a promise. Therefore, I should be able to catch errors in an async function like so:

const castSession = cast.framework.CastContext.getInstance().getCurrentSession();

const mediaInfo = new chrome.cast.media.MediaInfo(
  'https://example.com/stream.m3u8',
  'application/vnd.apple.mpegurl'
);

const loadRequest = new chrome.cast.media.LoadRequest(mediaInfo);

try {
  await castSession.getSessionObj().loadMedia(loadRequest);
} catch(e) {
  console.error(e);
}

Unfortunately, this doesn't work. Whatever load error I'm getting seems to occur sometime between the downloading of the HLS manifest and before playback. The loadMedia() promise resolves successfully, so there's no error to catch. The sender's developer console has an error:

cast_sender.js:85 Uncaught TypeError: d is not a function
    at cast_sender.js:85
    at V.onMessage (cast_sender.js:91)
    at S.h (cast_sender.js:71)
(anonymous) @ cast_sender.js:85
V.onMessage @ cast_sender.js:91
S.h @ cast_sender.js:71

Clearly, some sort of error is making it back to the client, and it seems that there should be some event handler that isn't set, but I don't see any documentation for how to catch the error.

How can I catch media load errors, general media errors, and any other errors on the Chromecast sender?

Hoang Dao

chrome.cast.Session and cast.framework.CastSession are different. While CastSession methods returns promises, Session object works with callback. The error occurs because of missing callback when calling session.loadMedia()

In your case, you have to check docs of chrome.cast.Session object for further operation, or continue your work by calling directly loadMedia from your CastSession object:

Option 1: continue your work with CastSession object:

try {
  await castSession.loadMedia(loadRequest);
} catch(e) {
  console.error(e);
}

Option 2: Work with Session object

try {
  const sessionObj = await castSession.getSessionObj();
  await (new Promise((res) => {
    sessionObj.loadMedia(loadRequest, res);
  }));
} catch(e) {
  console.error(e);
}

More info:

https://developers.google.com/cast/docs/reference/chrome/cast.framework.CastSession https://developers.google.com/cast/docs/reference/chrome/chrome.cast.Session

この記事はインターネットから収集されたものであり、転載の際にはソースを示してください。

侵害の場合は、連絡してください[email protected]

編集
0

コメントを追加

0

関連記事

分類Dev

Chromecast Web Sender API:オーディオトラックを切り替える

分類Dev

How to detect if Chromecast is already connected on Android Sender?

分類Dev

Handling two consecutive errors

分類Dev

Handling multiple errors in go

分類Dev

Elixir/Phoenix handling erlang errors

分類Dev

Catching and handling backend errors in Angular

分類Dev

handling unicode encode errors in python

分類Dev

Handling Errors in PocketSphinx Android app

分類Dev

Connexion class based handling

分類Dev

Handling errors with clojure core.async pipeline

分類Dev

Handling AWS Lambda errors with API Gateway

分類Dev

Customize errors handling in uu-parsinglib in Haskell

分類Dev

Azure Webjobs SDK and Queue handling errors

分類Dev

Outlook download attachments with MAPI python based on date, sender and subject line

分類Dev

Installing web.go errors

分類Dev

Web scraper return multiple errors

分類Dev

Load a web page

分類Dev

pipenv install giving Failed to load paths errors

分類Dev

Track JS CSS Asset Errors on page load

分類Dev

$http error handling: distinguishing user offline from other errors

分類Dev

msal.js angular 6 SPA callback and errors handling

分類Dev

react-hook-form handling server-side errors in handleSubmit

分類Dev

try/catch error handling in web app

分類Dev

Freenas rsync error: some files/attrs were not transferred (see previous errors) (code 23) at main.c(1053) [sender=3.0.9]

分類Dev

Chromecast MediaRouteProviderService

分類Dev

how to load JWPlayer in web page

分類Dev

Load parquet folders to spark dataframe based on condition

分類Dev

Load a specific Android library based on API version

分類Dev

Conditional execution based on database load (Oracle database)

Related 関連記事

  1. 1

    Chromecast Web Sender API:オーディオトラックを切り替える

  2. 2

    How to detect if Chromecast is already connected on Android Sender?

  3. 3

    Handling two consecutive errors

  4. 4

    Handling multiple errors in go

  5. 5

    Elixir/Phoenix handling erlang errors

  6. 6

    Catching and handling backend errors in Angular

  7. 7

    handling unicode encode errors in python

  8. 8

    Handling Errors in PocketSphinx Android app

  9. 9

    Connexion class based handling

  10. 10

    Handling errors with clojure core.async pipeline

  11. 11

    Handling AWS Lambda errors with API Gateway

  12. 12

    Customize errors handling in uu-parsinglib in Haskell

  13. 13

    Azure Webjobs SDK and Queue handling errors

  14. 14

    Outlook download attachments with MAPI python based on date, sender and subject line

  15. 15

    Installing web.go errors

  16. 16

    Web scraper return multiple errors

  17. 17

    Load a web page

  18. 18

    pipenv install giving Failed to load paths errors

  19. 19

    Track JS CSS Asset Errors on page load

  20. 20

    $http error handling: distinguishing user offline from other errors

  21. 21

    msal.js angular 6 SPA callback and errors handling

  22. 22

    react-hook-form handling server-side errors in handleSubmit

  23. 23

    try/catch error handling in web app

  24. 24

    Freenas rsync error: some files/attrs were not transferred (see previous errors) (code 23) at main.c(1053) [sender=3.0.9]

  25. 25

    Chromecast MediaRouteProviderService

  26. 26

    how to load JWPlayer in web page

  27. 27

    Load parquet folders to spark dataframe based on condition

  28. 28

    Load a specific Android library based on API version

  29. 29

    Conditional execution based on database load (Oracle database)

ホットタグ

アーカイブ