Table of Contents

Class NodeTracks

Namespace
Nyra
Assembly
Nyra.dll

Decoding, encoding and streaming of the tracks of a node.

public sealed class NodeTracks
Inheritance
NodeTracks
Inherited Members

Methods

DecodeAsync(string, CancellationToken)

Decodes a base64 track through the server (with its metadata), Decode(string) skips the server call for tracks this library understands.

public Task<Track> DecodeAsync(string encodedTrack, CancellationToken cancellationToken = default)

Parameters

encodedTrack string

The base64 track to decode.

cancellationToken CancellationToken

A token to cancel the operation.

Returns

Task<Track>

The decoded track.

Exceptions

IncompatibleServerException

The server's /v4/info version is not supported.

DecodeManyAsync(IEnumerable<string>, CancellationToken)

Decodes base64 tracks, contacting the server.

public Task<IReadOnlyList<Track>> DecodeManyAsync(IEnumerable<string> encodedTracks, CancellationToken cancellationToken = default)

Parameters

encodedTracks IEnumerable<string>

The base64 tracks to decode.

cancellationToken CancellationToken

A token to cancel the operation.

Returns

Task<IReadOnlyList<Track>>

The decoded tracks, in the order they were given.

Exceptions

IncompatibleServerException

The server's /v4/info version is not supported.

EncodeAsync(TrackInfo, CancellationToken)

Encodes track information into a base64 track the node can play.

public Task<string> EncodeAsync(TrackInfo info, CancellationToken cancellationToken = default)

Parameters

info TrackInfo

The track info to encode.

cancellationToken CancellationToken

A token to cancel the operation.

Returns

Task<string>

The encoded base64 track.

Remarks

NodeLink only.

Exceptions

NotSupportedException

The node is not NodeLink.

IncompatibleServerException

The server's /v4/info version is not supported.

EncodeManyAsync(IEnumerable<TrackInfo>, CancellationToken)

Encodes track information into base64 tracks the node can play.

public Task<IReadOnlyList<string>> EncodeManyAsync(IEnumerable<TrackInfo> infos, CancellationToken cancellationToken = default)

Parameters

infos IEnumerable<TrackInfo>

The track infos to encode.

cancellationToken CancellationToken

A token to cancel the operation.

Returns

Task<IReadOnlyList<string>>

The encoded base64 tracks, in the order they were given.

Remarks

NodeLink only.

Exceptions

NotSupportedException

The node is not NodeLink.

IncompatibleServerException

The server's /v4/info version is not supported.

GetStreamUrlAsync(Track, int?, CancellationToken)

Resolves the direct stream URL of a track's audio.

public Task<TrackStreamUrl> GetStreamUrlAsync(Track track, int? itag = null, CancellationToken cancellationToken = default)

Parameters

track Track

The track to resolve.

itag int?

The itag to resolve for, null lets the server pick.

cancellationToken CancellationToken

A token to cancel the operation.

Returns

Task<TrackStreamUrl>

The resolved stream URL and format.

Remarks

The server picks a default format when no itag is given. The resolved URL is short-lived, re-resolve it instead of caching it.

Exceptions

ArgumentNullException

track is null.

ArgumentException

The track carries a null or empty encoded form.

ArgumentOutOfRangeException

itag is negative.

RestException

The route is disabled on the server, or the track failed to resolve.

NodeUnreachableException

The transport failed before an answer arrived.

TimeoutException

The node's REST endpoint did not answer within its bound.

NotSupportedException

The node is not NodeLink.

IncompatibleServerException

The server's /v4/info version is not supported.

OpenAudioStreamAsync(Track, int, TimeSpan?, FilterChain?, LoadStreamFormat, CancellationToken)

Opens the decoded audio of a track as a readable stream, played through the node's audio pipeline with the given volume, start position and filter chain.

public Task<Stream> OpenAudioStreamAsync(Track track, int volume = 100, TimeSpan? position = null, FilterChain? filters = null, LoadStreamFormat format = LoadStreamFormat.Raw, CancellationToken cancellationToken = default)

Parameters

track Track

The track to stream.

volume int

The playback volume, 0-1000, 100 is the neutral value.

position TimeSpan?

Where in the track the stream starts.

filters FilterChain

The filter chain applied to the stream, null streams unfiltered.

format LoadStreamFormat

The container format of the stream, raw PCM by default. Only Raw and Wav are valid, any other value is rejected before the first request.

cancellationToken CancellationToken

A token to cancel the operation.

Returns

Task<Stream>

The audio stream of the track, the caller must dispose it.

Remarks

The caller owns the returned stream.

Exceptions

ArgumentNullException

track is null.

ArgumentOutOfRangeException

volume is outside 0-1000, position is negative, or format is not Raw or Wav.

RestException

The route is disabled on the server, or the track failed to load.

NodeUnreachableException

The transport failed before an answer arrived.

TimeoutException

The node's REST endpoint did not answer within its bound.

NotSupportedException

The node is not NodeLink, or the node is a NodeLink older than 3.10.0 and format is Wav.

IncompatibleServerException

The server's /v4/info version is not supported.