radio组件
This is a web component that plays channels from Radio4000. It uses the public radio4000-api and Vue.js.
这是一个播放Radio4000频道的Web组件。 它使用公共radio4000-api和Vue.js。
You can load the player with a CDN, like this:
您可以使用CDN加载播放器,如下所示:
<script async src="https://cdn.jsdelivr.net/npm/radio4000-player"></script>
<radio4000-player channel-slug="good-time-radio"></radio4000-player>
OR, you can use a package manager:
或者,您可以使用包管理器:
// npm install radio4000-player
import 'radio4000-player'
// now you can use <radio4000-player> in your templates
OR, you can use an iframe (source):
或者,您可以使用iframe( 源 ):
<iframe src="https://api.radio4000.com/embed?slug=detecteve" width="320" height="500" frameborder="0"></iframe>
Here's a complete list of all the attributes you can set and change on the web component. These do not affect the iframe version.
这是您可以在Web组件上设置和更改的所有属性的完整列表。 这些不会影响iframe版本。
Attribute | Type | Description |
---|---|---|
channel-slug | string | Radio4000 channel slug (ex: oskar ) |
channel-id | string | Radio4000 channel id (ex: -JYZvhj3vlGCjKXZ2cXO ) |
track-id | string | Radio4000 track id (ex: -JYEosmvT82Ju0vcSHVP ) |
volume | integer | from 0 to 100 (default: 100 ) |
autoplay | boolean | if it should start playing automatically (default: false ) |
shuffle | boolean | if tracks should be shuffled (default: false ) |
属性 | 类型 | 描述 |
---|---|---|
通道鼻塞 | string | Radio4000通道塞(例如: oskar ) |
频道编号 | string | Radio4000频道ID(例如: -JYZvhj3vlGCjKXZ2cXO ) |
轨道编号 | string | Radio4000轨道ID(例如: -JYEosmvT82Ju0vcSHVP ) |
卷 | integer | 从0到100(默认值: 100 ) |
自动播放 | boolean | 是否应该自动开始播放(默认值: false ) |
洗牌 | boolean | 是否应改组轨道(默认值: false ) |
Remember that HTML attributes are dasherized channel-slug
whereas JavaScript expects CamelCase channelSlug
.
请记住,HTML属性是反斜线的channel-slug
而JavaScript需要CamelCase channelSlug
。
var player = document.querySelector('radio4000-player')
// Load radio channel either by slug or id.
player.channelSlug = 'sugar-hiccup'
player.channelId = '-JYZvhj3vlGCjKXZ2cXO'
// Load a specific track.
player.trackId = '-JYEosmvT82Ju0vcSHVP'
// Change the volume.
player.volume = 25
// Enable shuffle.
player.shuffle = true
To enable autoplay:
要启用自动播放:
<radio4000-player channel-slug="200ok" autoplay="true"></radio4000-player>
You can listen for events directly on each <radio4000-player>
element.
您可以直接在每个<radio4000-player>
元素上侦听事件。
trackChanged
- This event fires whenever the current track is
trackChanged
每当当前轨道为
track
objects,
track
物体
previousTrack
and track
previousTrack
和track
trackEnded
- This event fires when the current track finishes
trackEnded
当前轨道结束时触发此事件
track
object.
track
对象。
mediaNotAvailable
- This event fires when a track could not be
mediaNotAvailable
当无法跟踪时触发此事件
track
track
# unrelated example of an HTTP query to Youtube api for details about
a video (replace `YOUTUBE_API_KEY` and `YOUTUBE_VIDEO_ID`)
GET https://www.googleapis.com/youtube/v3/videos?key=YOUTUBE_API_KEY&id=YOUTUBE_VIDEO_ID&fields=items(id,snippet,contentDetails,statistics)&part=snippet,contentDetails,statistics
Here's an example of how to listen for the trackChanged
event. It is the same approach for all events. In the case of both trackChanged
and trackEnded
, the event.detail[0]
argument will be a Radio4000 track
object.
这是一个如何监听trackChanged
事件的trackChanged
。 所有事件都采用相同的方法。 对于trackChanged
和trackEnded
, event.detail[0]
参数将是Radio4000 track
对象。
var player = document.querySelector('radio4000-player')
player.addEventListener('trackChanged', (event) => {
console.info('trackChanged event', event.detail[0])
// { track: { [...] } }
})
Danger zone. We are still finalizing the API for methods so except this to change.
危险区。 我们仍在敲定方法的API,因此除了更改之外。
// Get access to the Vue component behind the web component to access methods.
var player = document.querySelector('radio4000-player')
var vue = player.__vue_custom_element__.$children[0]
var tracks = [
{
id: 'uniqueId',
title: 'A title to display',
url: 'an url to link to in the track list',
ytid: 'an id to the youtube video'
}
];
var playlist = {
title: `A title for this list`,
image: 'https://raw.githubusercontent.com/internet4000/assets/master/radio4000/icon-r4.svg',
tracks: tracks
};
vue.updatePlaylist(playlist)
If the playlist object contains a query
string it will be shown on top of the track list.
如果播放列表对象包含query
字符串,它将显示在曲目列表的顶部。
If this player is used inside radio4000.com, we want the links to switch URL internally. For that you can use the boolean property r4-url
like so.
如果在radio4000.com内部使用此播放器,我们希望链接在内部切换URL。 为此,您可以像这样使用布尔属性r4-url
。
<radio4000-player r4-url="true"></radio4000-player>
Therefore, URLs in the player header won't open new browser window but will just replace the URL like Ember router would have done.
因此,播放器标题中的URL不会打开新的浏览器窗口,而只会像Ember路由器那样替换URL。
Feature branches are made from the master
branch.
功能分支由master
分支构成。
production
branch is used for the production version releases.
production
分支用于生产版本发行版。
# 1. clone and install dependencies
git clone[email protected]:internet4000/radio4000-player.git
yarn
# 2. starts a server on http://localhost:4002 that autobuilds when files change
yarn start
# run tests once
yarn test
# (re)run tests as files change
yarn start; yarn cypress open
Release a new patch e.g. 1.0.4
to 1.0.5
.
发布一个新补丁,例如1.0.4
到1.0.5
。
yarn release
Release a minor, major, or specific version:
发行次要,主要或特定版本:
yarn release minor
yarn release major
yarn release 0.8.3
翻译自: https://vuejsexamples.com/a-web-component-for-playing-embed-of-radio4000-channels-and-more/
radio组件