repositories {
...
maven {
maven { url 'https://repo.repsy.io/mvn/speechkitio/speechkit_io' }
}
}
ext {
// These 2 properties should be stored in your device gradle properties file and should contain your GitHub PAT user and token
getGithubUser = { project.properties["GITHUB_USER"] }
getGithubToken = { project.properties["GITHUB_TOKEN"] }
}
repositories {
...
maven {
name = "GitHubPackages"
url = uri("https://maven.pkg.github.com/SpeechKit/beyondwords-android-sdk-public")
credentials {
username = getGithubUser()
password = getGithubToken()
}
}
}
Next add a dependency in the build.gradle
file of your app module. The
following will add a dependency to the library:
implementation 'io.beyondwords.android:player:2.X.X'
where 2.X.X
is your preferred version.
Currently available version is 2.1.0
.
If not enabled already, you also need to turn on Java 8 support in all
build.gradle
files depending on the BeyondWords SDK by adding the following to the
android
section:
compileOptions {
targetCompatibility JavaVersion.VERSION_1_8
}
To instantiate a Player
you have to use the PlayerBuilder
contained in the SDK:
A PlayerBuilder
instance is created from one of the following functions
val builder = PlayerBuilder.forPodcastId(context, 1234, 5678)
Context used to create the Player
Id of the BeyondWords project ID
BeyondWords podcast ID
val builder = PlayerBuilder.forExternalId(context, 1234, "external id")
Context used to create the Player
Id of the BeyondWords project ID
The internal article ID
val builder = PlayerBuilder.forArticleUrl(context, 1234, "article url")
Context used to create the Player
Id of the BeyondWords project ID
The article url
import io.beyondwords.player.Player
import io.beyondwords.player.PlayerBuilder
val player = PlayerBuilder.forExternalId(context, projectid, externalid)
.setPendingIntent(createPendingLaunchIntent())
.enableUi(true)
.setNotificationChannelId("notificationChannelId")
.setNotificationId(1234)
.setNotificationChannelNameId(R.string.my_custom_channel_name)
.setNotificationChannelDescriptionId(R.string.my_custom_channel_description)
.setNotificationSmallIconId(R.drawable.my_custom_small_notification_icon)
.setNotificationLargeIconId(R.drawable.my_custom_large_notification_icon)
.build()
...
val player = PlayerBuilder.forExternalId(...).build()
player.addListener(object::Player.EventListener() {
override void onPrepare() {}
override void onPlay(duration: Float, progress: Float, advertiser: String?, adUrl: String?) { }
override void onPause(durationSec: Float, progressSec: Float) {}
override void onTimeUpdate(durationSec: Float, progressSec: Float) {}
override void onPlaybackRate(rate: Float) {}
override void onEnded() {}
})
The SDK also contains a UI-component: PlaybackControlView
.
import io.beyondwords.player.PlaybackControlView
To use it simply instantiate it directly and add to the current view hierarchy, or just add it to your xml layout.
Then bind the player and playback control view:
import io.beyondwords.player.Player
import io.beyondwords.player.PlayerBuilder
import io.beyondwords.player.PlaybackControlView
...
var player = PlayerBuilder.forExternalId(...).build()
...
val control = new PlaybackControlView(context)
control.setPlayer(player)
...
control.setPlayer(null)
...
player?.release()
player = null
This can be done in a similar way to play a podcast, you can specify either by using an external id, podcast id or an article url.
import io.beyondwords.player.Player;
val podcastRetriever = PodcastRetriever()
// To fetch via an external id
podcastRetriever.getViaExternalId(projectId, externalId, listener)
// To fetch via an podcast id
podcastRetriever.getViaPodcastId(projectId, podcastId, listener)
// To fetch via an article url
podcastRetriever.getViaArticleUrl(projectId, articleUrl, listener)
The player can be styled from either code, xml or overriding xml resources
Code | XML | Resource override |
---|---|---|
playbackControlView.setRoundedProgressCorners | app:bw_rounded_progress_corners="false" | <bool name="bw_progress_rounded_corners"></bool> |
playbackControlView.setBackgroundColour | app:bw_background_colour | <color name="bw_background_colour"></color> |
playbackControlView.setTitleTextColour | app:bw_title_text_colour | <color name="bw_title_text_colour"></color> |
playbackControlView.setTitleLinkTextColour | app:bw_title_link_colour | <color name="bw_title_link_text_colour"></color> |
playbackControlView.setSpeedTextColour | app:bw_speed_text_colour | <color name="bw_speed_text_colour"></color> |
playbackControlView.setProgressTextColour | app:bw_progress_text_colour | <color name="bw_progress_text_colour"></color> |
playbackControlView.setPlayPauseColour | app:bw_play_pause_colour | <color name="bw_play_button_colour"></color> |
playbackControlView.setFastForwardRewindIconColour | app:bw_ff_rewind_icon_colour | <color name="bw_ff_rewind_icon_colour"></color> |
playbackControlView.setFastForwardRewindDisplayed | app:bw_ff_rewind_icon_displayed | <bool name="bw_ff_rewind_icon_displayed"></bool> |
playbackControlView.setBackgroundCornerRadius | app:bw_background_corner_radius | <dimen name="bw_background_corner_radius"></dimen> |
playbackControlView.setProgressHeight | app:bw_progress_height | <dimen name="bw_progress_height"></dimen> |
playbackControlView.setProgressBackgroundColour | app:bw_progress_background_colour | <color name="bw_progress_background_colour"></color> |
playbackControlView.setProgressPlayedColour | app:bw_progress_played_colour | <color name="bw_progress_played_colour"></color> |
playbackControlView.setProgressBufferedColour | app:bw_progress_buffered_colour | <color name="bw_progress_buffered_colour"></color> |
playbackControlView.updatePlayPauseIcons | app:bw_play_button_img and app:bw_pause_button_img | R.drawable.ic_bw_play and R.drawable.ic_bw_pause |
A small helper class to anchor a player to the top or bottom of a ViewGroup
PlayerAnchorHelper.anchorPlayer(
anchorToView = <view group to add helper inside>,
playbackControlView = <player view to anchor>,
anchor = <PlayerAnchor.TOP or PlayerAnchor.BOTTOM>
)
Run the following command in the terminal:
git clone https://github.com/SpeechKit/beyondwords-android-sdk-public.git ./beyondwords_sdk_demo
Then import the project to Android Studio:
File -> New -> Import Project… (navigate to beyondwords_sdk_demo dir)
PendingIntent
to launch when clicking on the notification.
Flag to toggle whether a notification should be shown or not.
Set the notification channel id.
Set the notification id.
App string resource for the channel name id .
App string resource for the channel description id.
App drawable resource for the small notification icon.
App drawable resource for the large notification icon.
Releases the player. This must be called when the player is no longer required. The player must not be used after calling this method.
Register a listener to receive events from the player. The listener's methods will be called on the thread that was used to construct the player. However, if the thread used to construct the player does not have a Looper, then the listener will be called on the main thread.
Unregister a listener. The listener will no longer receive events from the player.
Whether the player is prepared.
Whether the player is ready for playback.
Whether the player is playing.
Determine if the player is currently paused.
Determine if the player has ended.
Begin playback of the audio.
Pause audio playback
Fast forward the audio playback by 10 seconds
Rewind the audio playback by 10 seconds
Moves to a new location in the media
positionMs
Position to move to, in milliseconds
Get the current time, in seconds
Returns an estimate of the position in the current content up to which data is buffered, in seconds.
Get the total duration of the audio article, in seconds
Get the time remaining on the audio article, in seconds
Check whether we're playing an unskippable ad
Get the playback rate
Set the playback rate
Get the Player
used in the view
Set the Player
used in the view
Set the colour of the play/pause buttons
Set the colour of the title text
Set the colour of the title link text
Set the colour of the progress text
Set the colour of the playback speed text
Set the colour of the player background
Set the background corner radius
Set the colour of the fast-forward/rewind icons
Flag to display or hide the fast-forward/rewind buttons.
Set if the progress has rounded corners or not.
Set the height of the playback progress bar
Set the colour of the progress buffered section
Set the colour of the progress played section
Set the colour of the progress unplayed section
Set the colour of the progress background
Update the icons of the play and pause buttons
Set the listener to receive updates for playback progress
Set the time bar minimum update interval
Show the player UI
Hide the player UI
Reset the player UI styling to the default values.