Class: Ipod::Track
- Inherits:
-
OpenStruct
- Object
- OpenStruct
- Ipod::Track
- Defined in:
- lib/ipod/track.rb
Constant Summary collapse
- FinishedProgress =
0.97
- SecondsPerTick =
0.256
Class Method Summary collapse
Instance Method Summary collapse
- #absolute_path ⇒ Object
- #exists? ⇒ Boolean
- #finished? ⇒ Boolean
- #length ⇒ Object
- #pos ⇒ Object
- #progress ⇒ Object
Class Method Details
.sec_to_ticks(sec) ⇒ Object
49 50 51 |
# File 'lib/ipod/track.rb', line 49 def self.sec_to_ticks(sec) sec / SecondsPerTick end |
.ticks_to_sec(ticks) ⇒ Object
53 54 55 |
# File 'lib/ipod/track.rb', line 53 def self.ticks_to_sec(ticks) ticks * SecondsPerTick end |
Instance Method Details
#absolute_path ⇒ Object
11 12 13 |
# File 'lib/ipod/track.rb', line 11 def absolute_path File.join ipod_root, filename end |
#exists? ⇒ Boolean
15 16 17 |
# File 'lib/ipod/track.rb', line 15 def exists? @exists ||= File.exists? absolute_path end |
#finished? ⇒ Boolean
19 20 21 |
# File 'lib/ipod/track.rb', line 19 def finished? (playcount and playcount > 0) or progress > FinishedProgress end |
#length ⇒ Object
31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 |
# File 'lib/ipod/track.rb', line 31 def length return @length if @length # if file is writable TagLib opens it read-write and appears to write something when the file # gets closed, or in any case closing a file open read-write is slow on slow media. # # if file is readonly TagLib still opens it but closing is much faster. # old_stat = File::Stat.new(absolute_path) begin FileUtils.chmod('a-w', absolute_path) quietly { return @length = TagLib::FileRef.open(absolute_path){|file| file.audio_properties.length} } ensure FileUtils.chmod(old_stat.mode, absolute_path) end end |
#pos ⇒ Object
27 28 29 |
# File 'lib/ipod/track.rb', line 27 def pos Track.ticks_to_sec(bookmarktime || 0.0) end |
#progress ⇒ Object
23 24 25 |
# File 'lib/ipod/track.rb', line 23 def progress pos / length end |