Class: Shoes::VideoVlc
- Inherits:
-
Object
show all
- Includes:
- Vlc
- Defined in:
- lib/shoes/videoffi.rb
Constant Summary
Constants included
from Vlc
Vlc::Audio_track, Vlc::LIBVLC_TRACK_AUDIO, Vlc::LIBVLC_TRACK_TEXT, Vlc::LIBVLC_TRACK_UNKNOWN, Vlc::LIBVLC_TRACK_VIDEO, Vlc::Media_stats, Vlc::Media_track, Vlc::Subtitle_track, Vlc::VLC_FUNCTIONS_MAP, Vlc::Video_track
Instance Attribute Summary collapse
Instance Method Summary
collapse
Methods included from Vlc
extern, import_symbols, load_lib, vlc_import_done
Constructor Details
#initialize(app, path, attr = nil) ⇒ VideoVlc
Returns a new instance of VideoVlc.
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
|
# File 'lib/shoes/videoffi.rb', line 234
def initialize(app, path, attr=nil)
@path = path
attr ||= {}
@autoplay = attr[:autoplay] || false
Vlc.load_lib unless Vlc.vlc_import_done
@version = libvlc_get_version
opts = attr.delete(:vlc_options)
sz, args = 0, nil
if opts
sz = opts.size
args = opts.pack("p#{sz}")
end
@vlci = libvlc_new(sz, args)
if @vlci.null?
upraise "Unable to initialize libvlc\nlibvlc_new() failed with :vlc_options => #{opts.inspect}\n" \
"and returned : \n#{@vlci.inspect}"
end
@player = libvlc_media_player_new(@vlci)
@list_player = libvlc_media_list_player_new(@vlci)
libvlc_media_list_player_set_media_player(@list_player, @player)
@medialist = libvlc_media_list_new(@vlci)
libvlc_media_list_player_set_media_list(@list_player, @medialist)
@loaded = load_media @path
vol = attr[:volume] || 85
libvlc_audio_set_volume(@player, vol)
attr[:video_width] = video_track_width if video_track_width
attr[:video_height] = video_track_height if video_track_height
@video = app.video_c attr
@wait_ready = app.animate(100) do |fr|
if @video.drawable_ready?
@wait_ready.stop
drID = @video.drawable case RUBY_PLATFORM
when /linux/
if libvlc_media_player_get_xwindow(@player) == 0
libvlc_media_player_set_xwindow(@player, drID)
end
when /mingw/
if libvlc_media_player_get_hwnd(@player).null?
libvlc_media_player_set_hwnd(@player, drID)
end
when /darwin/
if libvlc_media_player_get_nsobject(@player).null?
libvlc_media_player_set_nsobject(@player, drID)
end
end
unless RUBY_PLATFORM =~ /darwin/
libvlc_video_set_mouse_input(@player, 0)
libvlc_video_set_key_input(@player, 0)
end
play if @loaded && @autoplay
@wait_ready.remove
@wait_ready = nil
end
end
end
|
Instance Attribute Details
#autoplay ⇒ Object
Returns the value of attribute autoplay.
230
231
232
|
# File 'lib/shoes/videoffi.rb', line 230
def autoplay
@autoplay
end
|
#have_audio_track ⇒ Object
Returns the value of attribute have_audio_track.
231
232
233
|
# File 'lib/shoes/videoffi.rb', line 231
def have_audio_track
@have_audio_track
end
|
#have_video_track ⇒ Object
Returns the value of attribute have_video_track.
231
232
233
|
# File 'lib/shoes/videoffi.rb', line 231
def have_video_track
@have_video_track
end
|
#loaded ⇒ Object
Returns the value of attribute loaded.
231
232
233
|
# File 'lib/shoes/videoffi.rb', line 231
def loaded
@loaded
end
|
#path ⇒ Object
Returns the value of attribute path.
231
232
233
|
# File 'lib/shoes/videoffi.rb', line 231
def path
@path
end
|
#player ⇒ Object
Returns the value of attribute player.
231
232
233
|
# File 'lib/shoes/videoffi.rb', line 231
def player
@player
end
|
#version ⇒ Object
Returns the value of attribute version.
231
232
233
|
# File 'lib/shoes/videoffi.rb', line 231
def version
@version
end
|
#video_track_height ⇒ Object
Returns the value of attribute video_track_height.
231
232
233
|
# File 'lib/shoes/videoffi.rb', line 231
def video_track_height
@video_track_height
end
|
#video_track_width ⇒ Object
Returns the value of attribute video_track_width.
231
232
233
|
# File 'lib/shoes/videoffi.rb', line 231
def video_track_width
@video_track_width
end
|
Instance Method Details
379
380
381
382
383
|
# File 'lib/shoes/videoffi.rb', line 379
def access_media_list
libvlc_media_list_lock(@medialist)
yield @medialist
libvlc_media_list_unlock(@medialist)
end
|
#displace(x, y) ⇒ Object
502
|
# File 'lib/shoes/videoffi.rb', line 502
def displace(x, y); @video.displace(x, y); end
|
#height ⇒ Object
505
|
# File 'lib/shoes/videoffi.rb', line 505
def height; @video.height; end
|
#hide ⇒ Object
485
|
# File 'lib/shoes/videoffi.rb', line 485
def hide; @video.hide; end
|
#left ⇒ Object
506
|
# File 'lib/shoes/videoffi.rb', line 506
def left; @video.left; end
|
#length ⇒ Object
430
431
432
433
|
# File 'lib/shoes/videoffi.rb', line 430
def length
libvlc_media_player_get_length(@player) end
|
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
|
# File 'lib/shoes/videoffi.rb', line 311
def load_media(path)
@have_video_track = @have_audio_track = nil
@video_track_width = @video_track_height = nil
return nil if @path.empty?
@media =
if path =~ %r{://}
libvlc_media_new_location(@vlci, path)
else
upraise "Sorry, That File doesn't exists :\n#{path} !" unless File.exists? path
libvlc_media_new_path(@vlci, path)
end
if @media.null? upraise "Sorry, i can't load that media! :\n#{path}"
end
access_media_list do |medialist|
libvlc_media_list_remove_index(medialist, 0) if (libvlc_media_list_count(medialist) != 0)
libvlc_media_list_add_media(medialist, @media);
end
libvlc_media_parse(@media)
tracks_buf = Fiddle::Pointer.malloc(Media_track.size)
n_tracks = libvlc_media_tracks_get( @media, tracks_buf.ref )
libvlc_media_release(@media)
ptr_size, unpkf = 8, 'Q' if Fiddle::SIZEOF_VOIDP == 4 ptr_size = 4
unpkf = 'L'
end
(0...n_tracks).each do |i|
tr_p = tracks_buf[ptr_size*i, ptr_size] tr_pa = tr_p.unpack(unpkf)[0] mdt = Media_track.new(tr_pa)
if mdt.i_type == LIBVLC_TRACK_VIDEO
@have_video_track = true
v = Video_track.new Fiddle::Pointer[mdt.kind]
@video_track_width = v.i_width
@video_track_height = v.i_height
end
if mdt.i_type == LIBVLC_TRACK_AUDIO
@have_audio_track = true
end
end
libvlc_media_tracks_release(tracks_buf, n_tracks);
true
end
|
#move(x, y) ⇒ Object
503
|
# File 'lib/shoes/videoffi.rb', line 503
def move(x, y); @video.move(x, y); end
|
455
456
457
458
|
# File 'lib/shoes/videoffi.rb', line 455
def next_media
r = libvlc_media_list_player_next(@list_player)
return r == 0 ? true : false
end
|
#parent ⇒ Object
487
|
# File 'lib/shoes/videoffi.rb', line 487
def parent; @video.parent; end
|
#pause ⇒ Object
408
409
410
|
# File 'lib/shoes/videoffi.rb', line 408
def pause
libvlc_media_list_player_pause(@list_player)
end
|
#play ⇒ Object
404
405
406
|
# File 'lib/shoes/videoffi.rb', line 404
def play
libvlc_media_list_player_play(@list_player)
end
|
#play_at(index) ⇒ Object
478
479
480
481
|
# File 'lib/shoes/videoffi.rb', line 478
def play_at(index)
r = libvlc_media_list_player_play_item_at_index(@list_player, index)
return r == 0 ? true : false
end
|
#play_list_add(path) ⇒ Object
470
471
472
473
474
475
476
|
# File 'lib/shoes/videoffi.rb', line 470
def play_list_add(path)
r = nil
access_media_list do |medialist|
r = libvlc_media_list_add_media(medialist, libvlc_media_new_path(@vlci, path))
end
r == 0 ? true : false
end
|
465
466
467
468
|
# File 'lib/shoes/videoffi.rb', line 465
def play_media(path)
media = libvlc_media_new_path(@vlci, path)
libvlc_media_list_player_play_item(@list_player, media)
end
|
#playing? ⇒ Boolean
416
417
418
|
# File 'lib/shoes/videoffi.rb', line 416
def playing?
libvlc_media_list_player_is_playing(@list_player) == 1 ? true : false
end
|
#position ⇒ Object
445
446
447
448
|
# File 'lib/shoes/videoffi.rb', line 445
def position
libvlc_media_player_get_position(@player)
end
|
#position=(pos) ⇒ Object
450
451
452
453
|
# File 'lib/shoes/videoffi.rb', line 450
def position=(pos)
libvlc_media_player_set_position(@player, pos)
end
|
460
461
462
463
|
# File 'lib/shoes/videoffi.rb', line 460
def previous_media
r = libvlc_media_list_player_previous(@list_player)
return r == 0 ? true : false
end
|
#remove ⇒ Object
488
489
490
491
492
493
494
495
496
|
# File 'lib/shoes/videoffi.rb', line 488
def remove
libvlc_media_list_release(@medialist)
libvlc_media_player_release(@player)
libvlc_media_list_player_release(@list_player)
libvlc_release(@vlci)
@vlci = @list_player = @player = @medialist = nil
@video.remove
@video = nil
end
|
#show ⇒ Object
redirecting to shoes C video methods
484
|
# File 'lib/shoes/videoffi.rb', line 484
def show; @video.show; end
|
#stop ⇒ Object
412
413
414
|
# File 'lib/shoes/videoffi.rb', line 412
def stop
libvlc_media_list_player_stop(@list_player)
end
|
#style(attrb = nil) ⇒ Object
498
499
500
501
|
# File 'lib/shoes/videoffi.rb', line 498
def style(attrb=nil)
return @video.style if attrb == nil
@video.style(attrb)
end
|
#time ⇒ Object
435
436
437
438
|
# File 'lib/shoes/videoffi.rb', line 435
def time
libvlc_media_player_get_time(@player)
end
|
#time=(time) ⇒ Object
440
441
442
443
|
# File 'lib/shoes/videoffi.rb', line 440
def time=(time)
libvlc_media_player_set_time(@player, time)
end
|
#toggle ⇒ Object
486
|
# File 'lib/shoes/videoffi.rb', line 486
def toggle; @video.toggle; end
|
509
|
# File 'lib/shoes/videoffi.rb', line 509
def tooltip; @video.tooltip; end
|
510
|
# File 'lib/shoes/videoffi.rb', line 510
def tooltip=(tooltip); @video.tooltip = tooltip; end
|
#top ⇒ Object
507
|
# File 'lib/shoes/videoffi.rb', line 507
def top; @video.top; end
|
#volume ⇒ Object
420
421
422
423
|
# File 'lib/shoes/videoffi.rb', line 420
def volume
libvlc_audio_get_volume(@player)
end
|
#volume=(vol) ⇒ Object
425
426
427
428
|
# File 'lib/shoes/videoffi.rb', line 425
def volume=(vol)
libvlc_audio_set_volume(@player, vol)
end
|
#width ⇒ Object
widget width, not video track width
504
|
# File 'lib/shoes/videoffi.rb', line 504
def width; @video.width; end
|