Open a Story or Clips player from your own button, link, or route instead of a
tile. These methods are on Storyteller.sharedInstance. Each one returns a
promise that rejects when the SDK can't open the content. Call them after
initialize resolves.
constopenFeaturedStory=async()=>{try{awaitStoryteller.sharedInstance.openStory('story-id');}catch(error){console.error('The Story could not be opened.',error);}};document.getElementById('featured-story-button')?.addEventListener('click',openFeaturedStory);
The SDK first looks for the content in the views on your page and opens it in
that view's player. It uses only views whose player URLs are turned on, which
means the disableUrlstheme setting is false. If no view on
the page has the content, the SDK loads it from Storyteller and opens it in a
default player. Either way, the SDK opens the player by setting the page's hash
URL, such as #stories/story-id, and the promise resolves at that point. See
basename for the URL format.
Opens the Story player for a Category. Pass a Story ID as the second argument
to start at that Story; otherwise, the first Story in the Category opens.
Opens the Clips player for a collection. Pass a destination to start at a
Clip, or at the first Clip in a Clip Category. Otherwise, the first Clip in the
collection opens.
When the user arrived through a deep link, pass
Storyteller.OpenedReason.deepLink as the third argument so analytics events
report deepLink as the reason:
Call dismissPlayer to close the open Story or Clips player, for example when
your application navigates away. Pass true to play the close animation. If
no player is open, the call does nothing. It doesn't close a
StorytellerEmbeddedClipsPlayerView.
Wrap each call in try/catch, or add .catch(), so that a rejected promise
doesn't go unhandled. The rejection value can be an Error or a string.
Method
When the content is missing
openStory, openStoryByExternalId
Rejects when the Story request fails, or with a string when no Story has the ID.
openPage
Rejects when the SDK can't load a Story that contains the Page.
openCategory
Rejects when the SDK can't load the Category, or the Category has no Stories. If storyId isn't in the Category, the first Story opens instead.
openCollection
Rejects when the SDK can't load the collection, or the collection has no Clips. If the destination Clip or Category isn't in the collection, the first Clip opens instead.
openClipByExternalId
Rejects when the SDK can't load the collection, or with a string when the collection has no Clip with the external ID.
When the SDK opens the first Story or Clip instead of the one you asked for,
it logs a message. Call enableLogging to see it in the browser console.
{"slug": "open-player", "page_title": "Open a Player Programmatically", "page_url": "OpenPlayer/", "canonical_url": "/web/OpenPlayer/", "markdown": "# Open a player programmatically\n\nOpen a Story or Clips player from your own button, link, or route instead of a\ntile. These methods are on `Storyteller.sharedInstance`. Each one returns a\npromise that rejects when the SDK can't open the content. Call them after\n`initialize` resolves.\n\n```javascript\nconst openFeaturedStory = async () => {\n try {\n await Storyteller.sharedInstance.openStory('story-id');\n } catch (error) {\n console.error('The Story could not be opened.', error);\n }\n};\n\ndocument\n .getElementById('featured-story-button')\n ?.addEventListener('click', openFeaturedStory);\n```\n\nThe SDK first looks for the content in the views on your page and opens it in\nthat view's player. It uses only views whose player URLs are turned on, which\nmeans the `disableUrls` [theme setting](Themes.md) is `false`. If no view on\nthe page has the content, the SDK loads it from Storyteller and opens it in a\ndefault player. Either way, the SDK opens the player by setting the page's hash\nURL, such as `#stories/story-id`, and the promise resolves at that point. See\n[`basename`](StorytellerListView.md#basename) for the URL format.\n\n## Open a Story {#open-a-story}\n\n### openStory\n\nOpens a Story by its ID.\n\n```javascript\nawait Storyteller.sharedInstance.openStory('story-id');\n```\n\nFull signature: [`openStory`](AdditionalMethods.md#openstory).\n\n### openStoryByExternalId\n\nOpens a Story by its external ID.\n\n```javascript\nawait Storyteller.sharedInstance.openStoryByExternalId('story-external-id');\n```\n\nFull signature:\n[`openStoryByExternalId`](AdditionalMethods.md#openstorybyexternalid).\n\n### openPage\n\nOpens the Story that contains a Page, starting at that Page.\n\n```javascript\nawait Storyteller.sharedInstance.openPage('page-id');\n```\n\nFull signature: [`openPage`](AdditionalMethods.md#openpage).\n\n### openCategory\n\nOpens the Story player for a Category. Pass a Story ID as the second argument\nto start at that Story; otherwise, the first Story in the Category opens.\n\n```javascript\nawait Storyteller.sharedInstance.openCategory('category-id', 'story-id');\n```\n\nFull signature: [`openCategory`](AdditionalMethods.md#opencategory).\n\n## Open Clips {#open-clips}\n\n### openCollection\n\nOpens the Clips player for a collection. Pass a `destination` to start at a\nClip, or at the first Clip in a Clip Category. Otherwise, the first Clip in the\ncollection opens.\n\n```javascript\nawait Storyteller.sharedInstance.openCollection('collection-id');\n\nawait Storyteller.sharedInstance.openCollection('collection-id', {\n clipId: 'clip-id',\n});\n\nawait Storyteller.sharedInstance.openCollection('collection-id', {\n categoryId: 'clip-category-id',\n});\n```\n\nWhen the user arrived through a deep link, pass\n`Storyteller.OpenedReason.deepLink` as the third argument so analytics events\nreport `deepLink` as the reason:\n\n```javascript\nawait Storyteller.sharedInstance.openCollection(\n 'collection-id',\n { clipId: 'clip-id' },\n Storyteller.OpenedReason.deepLink\n);\n```\n\nFull signature: [`openCollection`](AdditionalMethods.md#opencollection).\n\n### openClipByExternalId\n\nOpens the Clips player for a collection, at the Clip with this external ID.\n\n```javascript\nawait Storyteller.sharedInstance.openClipByExternalId(\n 'collection-id',\n 'clip-external-id'\n);\n```\n\nFull signature:\n[`openClipByExternalId`](AdditionalMethods.md#openclipbyexternalid).\n\n## Close the player {#close-the-player}\n\nCall `dismissPlayer` to close the open Story or Clips player, for example when\nyour application navigates away. Pass `true` to play the close animation. If\nno player is open, the call does nothing. It doesn't close a\n`StorytellerEmbeddedClipsPlayerView`.\n\n```javascript\nif (Storyteller.sharedInstance.isPlayerVisible) {\n Storyteller.sharedInstance.dismissPlayer(true);\n}\n```\n\nFull signature: [`dismissPlayer`](AdditionalMethods.md#dismissplayer).\n\n## Handle errors {#handle-errors}\n\nWrap each call in `try`/`catch`, or add `.catch()`, so that a rejected promise\ndoesn't go unhandled. The rejection value can be an `Error` or a string.\n\n| Method | When the content is missing |\n| --- | --- |\n| `openStory`, `openStoryByExternalId` | Rejects when the Story request fails, or with a string when no Story has the ID. |\n| `openPage` | Rejects when the SDK can't load a Story that contains the Page. |\n| `openCategory` | Rejects when the SDK can't load the Category, or the Category has no Stories. If `storyId` isn't in the Category, the first Story opens instead. |\n| `openCollection` | Rejects when the SDK can't load the collection, or the collection has no Clips. If the `destination` Clip or Category isn't in the collection, the first Clip opens instead. |\n| `openClipByExternalId` | Rejects when the SDK can't load the collection, or with a string when the collection has no Clip with the external ID. |\n\nWhen the SDK opens the first Story or Clip instead of the one you asked for,\nit logs a message. Call `enableLogging` to see it in the browser console.\n\n## Next steps\n\n- [Use additional SDK methods](AdditionalMethods.md): full signatures for every method on this page\n- [Integrate analytics](Analytics.md): the events that each player sends when it opens\n- [Configure views](StorytellerListView.md#basename): hash URLs and `basename`\n", "copy_markdown_include_header": false, "base_path": "", "ai_dir": "ai", "missing_payload_behavior": "empty"}