unused / airstream

A command line tool for streaming to airplay-devices
628 stars 30 forks source link

Playing audio stream breaks due to progress bar #36

Closed hiviah closed 8 years ago

hiviah commented 8 years ago

This is similar to issue #30. If you try to play audio stream, it results in exception:

airstream http://ice1.somafm.com/groovesalad-128-aac -o appletv
loading can take a few seconds...
=> press [q] to exit airstream
Progress |=============================================================================================================================================================================================================================================| 100%

/usr/local/share/gems/gems/ruby-progressbar-1.1.1/lib/progress_bar/components/progressable.rb:82:in `validate_progress': You can't set the item's current value to be greater than the total. (RuntimeError)
        from /usr/local/share/gems/gems/ruby-progressbar-1.1.1/lib/progress_bar/components/progressable.rb:45:in `progress='
        from /usr/local/share/gems/gems/ruby-progressbar-1.1.1/lib/progress_bar/base.rb:131:in `with_progressables'
        from /usr/local/share/gems/gems/ruby-progressbar-1.1.1/lib/progress_bar/base.rb:48:in `block in progress='
        from /usr/local/share/gems/gems/ruby-progressbar-1.1.1/lib/progress_bar/base.rb:147:in `with_update'
        from /usr/local/share/gems/gems/ruby-progressbar-1.1.1/lib/progress_bar/base.rb:48:in `progress='
        from /usr/local/share/gems/gems/airstream-0.4.9/bin/airstream:102:in `<top (required)>'
        from /usr/local/bin/airstream:23:in `load'
        from /usr/local/bin/airstream:23:in `<main>'

One workaround is to disable the progress bar like this, but it's rather quick&dirty fix:

diff --git a/bin/airstream b/bin/airstream
index 834814f..a081d26 100755
--- a/bin/airstream
+++ b/bin/airstream
@@ -94,16 +94,11 @@ begin

   io.puts "=> press ["+Airstream::Io::KEY_QUIT+"] to exit airstream"
   Airstream::Io.hide_input
-  pbar = ProgressBar.create({ format: '%t |%b%i| %p%%', total: player.duration })
   begin # reconsider playing...
     sleep UPDATE_TIMEOUT
     formatted_time = Time.at(player.elapsed_time).gmtime.strftime('%R:%S')
-    pbar.title = "#{player.current_title} #{formatted_time}"
-    pbar.progress = player.elapsed_time
     io.catch_input
-    player.update io
   end until io.quit? || player.finished?
-  pbar.finish

 rescue Airplay::Protocol::InvalidMediaError
   STDERR.puts
unused commented 8 years ago

thx for the input - I added a fix that should prevent error for invalid progressbar values.