Stream and Validate fixes

This commit is contained in:
killer069
2021-10-05 18:47:09 +05:30
parent f30c4f458b
commit 79419d2205
5 changed files with 137 additions and 59 deletions

View File

@@ -2,6 +2,14 @@ export { playlist_info, video_basic_info, video_info, yt_validate, extractID, Yo
export { spotify, sp_validate, refreshToken, is_expired, Spotify } from './Spotify';
export { soundcloud, so_validate, SoundCloud, SoundCloudStream } from './SoundCloud';
enum AudioPlayerStatus {
Idle = 'idle',
Buffering = 'buffering',
Paused = 'paused',
Playing = 'playing',
AutoPaused = 'autopaused'
}
interface SearchOptions {
limit?: number;
source?: {
@@ -28,6 +36,7 @@ import { check_id, so_search, stream as so_stream, stream_from_info as so_stream
import { InfoData, stream as yt_stream, StreamOptions, stream_from_info as yt_stream_info } from './YouTube/stream';
import { SoundCloudTrack } from './SoundCloud/classes';
import { yt_search } from './YouTube/search';
import { EventEmitter } from 'stream';
/**
* Main stream Command for streaming through various sources
@@ -170,3 +179,14 @@ export function authorization(): void {
}
});
}
export function attachListeners(player: EventEmitter, resource: YouTubeStream | SoundCloudStream) {
player.on(AudioPlayerStatus.Paused, () => resource.pause());
player.on(AudioPlayerStatus.AutoPaused, () => resource.pause());
player.on(AudioPlayerStatus.Playing, () => resource.resume());
player.once(AudioPlayerStatus.Idle, () => {
player.removeListener(AudioPlayerStatus.Paused, () => resource.pause());
player.removeListener(AudioPlayerStatus.AutoPaused, () => resource.pause());
player.removeListener(AudioPlayerStatus.Playing, () => resource.resume());
});
}