App-DrivePlayer
view release on metacpan or search on metacpan
lib/App/DrivePlayer/Player.pm view on Meta::CPAN
);
$player->play({ drive_id => $file_id, title => 'Song' });
$player->pause_resume;
$player->seek(90); # jump to 1:30
$player->set_volume(80); # 0-100
$player->stop;
$player->quit; # terminate mpv
# Call periodically from a GUI timer:
$player->poll;
=head1 DESCRIPTION
Controls an C<mpv> subprocess via its JSON IPC socket. Audio files are
streamed directly from Google Drive using the Drive media URL with a Bearer
token injected as an HTTP header. The Bearer token is cached and
automatically refreshed after 55 minutes.
mpv is started lazily on the first call to L</play> and reused for
subsequent tracks.
=head1 ATTRIBUTES
=head2 auth
is: ro, required: 1
An authentication object with a C<headers()> method returning an arrayref
of the form C<['Authorization', 'Bearer TOKEN']> (e.g.
L<Google::RestApi::Auth::OAuth2Client>).
=head2 on_state_change
is: ro, isa: CodeRef, optional
Called with the new state string (C<'play'>, C<'pause'>, or C<'stop'>)
whenever the playback state changes. Not called when the state is set to
its current value.
=head2 on_track_end
is: ro, isa: CodeRef, optional
Called with no arguments when a track ends naturally (EOF) or is stopped
explicitly.
=head2 on_position
is: ro, isa: CodeRef, optional
Called by L</poll> with C<($position_seconds, $duration_seconds)> when both
values are available from mpv.
=head1 METHODS
=head2 new
my $player = App::DrivePlayer::Player->new(%args);
Constructor. C<auth> is required; all callbacks are optional.
=head2 play
$player->play(\%track);
Begin playing a track. C<%track> must contain at least C<drive_id>.
Starts mpv if it is not already running. Sets state to C<'play'>.
=head2 pause_resume
$player->pause_resume;
Toggle between C<'play'> and C<'pause'>. No-op when stopped.
=head2 stop
$player->stop;
Stop playback and set state to C<'stop'>. mpv remains running.
=head2 seek
$player->seek($seconds);
Seek to an absolute position in seconds. No-op when stopped.
=head2 set_volume
$player->set_volume($percent); # 0-100
Set the playback volume.
=head2 get_volume
my $pct = $player->get_volume;
Return the current volume (0-100). Returns C<50> if mpv is not responding.
=head2 state
my $state = $player->state; # 'play', 'pause', or 'stop'
Return the current playback state.
=head2 current_track
my $track = $player->current_track; # hashref or undef
Return the track hashref passed to the most recent L</play> call.
=head2 poll
$player->poll;
Query mpv for the current playback position and duration, firing the
C<on_position> callback if both are available. Also drains any pending
mpv events. Intended to be called from a periodic GUI timer.
=head2 quit
( run in 2.391 seconds using v1.01-cache-2.11-cpan-140bd7fdf52 )