Player.pm 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134
  1. package Plugins::SqueezeESP32::Player;
  2. use strict;
  3. use base qw(Slim::Player::SqueezePlay);
  4. use Digest::MD5 qw(md5);
  5. use List::Util qw(min);
  6. use Slim::Utils::Log;
  7. use Slim::Utils::Prefs;
  8. my $prefs = preferences('plugin.squeezeesp32');
  9. my $log = logger('plugin.squeezeesp32');
  10. sub model { 'squeezeesp32' }
  11. sub modelName { 'SqueezeESP32' }
  12. sub hasIR { 0 }
  13. sub init {
  14. my $client = shift;
  15. $client->SUPER::init(@_);
  16. $client->config_artwork();
  17. }
  18. # Allow the player to define it's display width (and probably more)
  19. sub playerSettingsFrame {
  20. my $client = shift;
  21. my $data_ref = shift;
  22. my $value;
  23. my $id = unpack('C', $$data_ref);
  24. # New SETD command 0xfe for display width & height
  25. if ($id == 0xfe) {
  26. $value = (unpack('Cn', $$data_ref))[1];
  27. if ($value > 100 && $value < 400) {
  28. $prefs->client($client)->set('width', $value);
  29. my $height = (unpack('Cnn', $$data_ref))[2];
  30. $prefs->client($client)->set('height', $height || 0);
  31. $client->display->modes($client->display->build_modes);
  32. $client->display->widthOverride(1, $value);
  33. $client->update;
  34. main::INFOLOG && $log->is_info && $log->info("Setting player $value" . "x" . "$height for ", $client->name);
  35. }
  36. }
  37. $client->SUPER::playerSettingsFrame($data_ref);
  38. }
  39. sub hasScrolling {
  40. return 1;
  41. }
  42. sub hasIR {
  43. return 1;
  44. }
  45. sub update_artwork {
  46. my $client = shift;
  47. my $cprefs = $prefs->client($client);
  48. my $artwork = $cprefs->get('artwork') || return;
  49. return unless $artwork->{'enable'};
  50. my $s = min($cprefs->get('height') - $artwork->{'y'}, $cprefs->get('width') - $artwork->{'x'});
  51. my $params = { force => shift || 0 };
  52. my $path = 'music/current/cover_' . $s . 'x' . $s . '_o.jpg';
  53. my $body = Slim::Web::Graphics::artworkRequest($client, $path, $params, \&send_artwork, undef, HTTP::Response->new);
  54. send_artwork($client, undef, \$body) if $body;
  55. }
  56. sub send_artwork {
  57. my ($client, $params, $dataref) = @_;
  58. # I'm not sure why we are called so often, so only send when needed
  59. my $md5 = md5($$dataref);
  60. return if $client->pluginData('artwork_md5') eq $md5 && !$params->{'force'};
  61. $client->pluginData('artwork', $dataref);
  62. $client->pluginData('artwork_md5', $md5);
  63. my $artwork = $prefs->client($client)->get('artwork') || {};
  64. my $length = length $$dataref;
  65. my $offset = 0;
  66. $log->info("got resized artwork (length: ", length $$dataref, ")");
  67. my $header = pack('Nnn', $length, $artwork->{'x'}, $artwork->{'y'});
  68. while ($length > 0) {
  69. $length = 1280 if $length > 1280;
  70. $log->info("sending grfa $length");
  71. my $data = $header . pack('N', $offset) . substr( $$dataref, 0, $length, '' );
  72. $client->sendFrame( grfa => \$data );
  73. $offset += $length;
  74. $length = length $$dataref;
  75. }
  76. }
  77. sub clear_artwork {
  78. my ($client, $request) = @_;
  79. my $artwork = $prefs->client($client)->get('artwork');
  80. if ($artwork && $artwork->{'enable'}) {
  81. main::INFOLOG && $log->is_info && $log->info("artwork stop/clear " . $request->getRequestString());
  82. $client->pluginData('artwork_md5', '');
  83. }
  84. }
  85. sub config_artwork {
  86. my ($client) = @_;
  87. if ( my $artwork = $prefs->client($client)->get('artwork') ) {
  88. my $header = pack('Nnn', $artwork->{'enable'}, $artwork->{'x'}, $artwork->{'y'});
  89. $client->sendFrame( grfa => \$header );
  90. }
  91. }
  92. sub reconnect {
  93. my $client = shift;
  94. $client->pluginData('artwork_md5', '');
  95. $client->SUPER::reconnect(@_);
  96. }
  97. 1;