Class: KodiClient::Methods::Player

Inherits:
KodiMethod show all
Defined in:
lib/kodi_client/methods/player.rb

Overview

contains all Kodi Application methods

Constant Summary collapse

ADD_SUBTITLE =
'Player.AddSubtitle'
OPEN =
'Player.Open'
GET_ACTIVE_PLAYER =
'Player.GetActivePlayers'
GET_ITEM =
'Player.GetItem'
GET_PLAYERS =
'Player.GetPlayers'
GET_PROPERTIES =
'Player.GetProperties'
GET_VIEW_MODE =
'Player.GetViewMode'
GO_TO =
'Player.GoTo'
MOVE =
'Player.Move'
ROTATE =
'Player.Rotate'
PLAY_PAUSE =
'Player.PlayPause'
SEEK =
'Player.Seek'
SET_AUDIO_STREAM =
'Player.SetAudioStream'
SET_PARTY_MODE =
'Player.SetPartymode'
SET_REPEAT =
'Player.SetRepeat'
SET_SPEED =
'Player.SetSpeed'
SET_SUBTITLE =
'Player.SetSubtitle'
SET_VIDEO_STREAM =
'Player.SetVideoStream'
SET_VIEW_MODE =
'Player.SetViewMode'
STOP =
'Player.Stop'
ZOOM =
'Player.Zoom'

Instance Method Summary collapse

Methods inherited from KodiMethod

#apply_options, #invoke_api

Instance Method Details

#add_subtitle(player_id, subtitle, kodi_id = 1) ⇒ Object



30
31
32
33
34
# File 'lib/kodi_client/methods/player.rb', line 30

def add_subtitle(player_id, subtitle, kodi_id = 1)
  request = KodiRequest.new(kodi_id, ADD_SUBTITLE, { 'playerid' => player_id, 'subtitle' => subtitle })
  json = invoke_api(request)
  KodiResponse.new(json)
end

#get_active_players(kodi_id = 1) ⇒ Object



36
37
38
39
40
41
42
# File 'lib/kodi_client/methods/player.rb', line 36

def get_active_players(kodi_id = 1)
  request = KodiRequest.new(kodi_id, GET_ACTIVE_PLAYER, {})
  json = invoke_api(request)
  result = Types::Player::Player.create_list(json['result'])
  json['result'] = result
  KodiResponse.new(json)
end

#get_item(player_id, properties = Types::List::ListFieldsAll.all_properties, kodi_id = 1) ⇒ Object



51
52
53
54
55
56
57
58
# File 'lib/kodi_client/methods/player.rb', line 51

def get_item(player_id, properties = Types::List::ListFieldsAll.all_properties, kodi_id = 1)
  request = KodiRequest.new(kodi_id, GET_ITEM, { 'playerid' => player_id,
                                                 'properties' => properties })
  json = invoke_api(request)
  result = Types::List::ListItemAll.create(json['result']['item'])
  json['result'] = result
  KodiResponse.new(json)
end

#get_players(media = Types::Media::MediaType::ALL, kodi_id = 1) ⇒ Object



60
61
62
63
64
65
66
# File 'lib/kodi_client/methods/player.rb', line 60

def get_players(media = Types::Media::MediaType::ALL, kodi_id = 1)
  request = KodiRequest.new(kodi_id, GET_PLAYERS, { 'media' => media })
  json = invoke_api(request)
  result = Types::Player::Player.create_list(json['result'])
  json['result'] = result
  KodiResponse.new(json)
end

#get_properties(player_id, properties = Types::Player::PropertyName.all_properties, kodi_id = 1) ⇒ Object



68
69
70
71
72
73
74
75
# File 'lib/kodi_client/methods/player.rb', line 68

def get_properties(player_id, properties = Types::Player::PropertyName.all_properties, kodi_id = 1)
  request = KodiRequest.new(kodi_id, GET_PROPERTIES, { 'playerid' => player_id,
                                                       'properties' => properties })
  json = invoke_api(request)
  result = Types::Player::PropertyValue.create(json['result'])
  json['result'] = result
  KodiResponse.new(json)
end

#get_view_mode(kodi_id = 1) ⇒ Object



77
78
79
80
81
82
83
# File 'lib/kodi_client/methods/player.rb', line 77

def get_view_mode(kodi_id = 1)
  request = KodiRequest.new(kodi_id, GET_VIEW_MODE, {})
  json = invoke_api(request)
  result = Types::Player::PlayerViewMode.create(json['result'])
  json['result'] = result
  KodiResponse.new(json)
end

#go_to(player_id, to = Types::Global::NextPrev::NEXT, kodi_id = 1) ⇒ KodiResponse

goes to the next/prev item or to a specific item in the playlist

Parameters:

  • player_id (String)
    • the player id

  • to (Integer/Types::Global::NextPrev) (defaults to: Types::Global::NextPrev::NEXT)
    • playlist position, or prev/next

  • kodi_id (Integer) (defaults to: 1)
    • the kodi id

Returns:



92
93
94
95
96
# File 'lib/kodi_client/methods/player.rb', line 92

def go_to(player_id, to = Types::Global::NextPrev::NEXT, kodi_id = 1)
  request = KodiRequest.new(kodi_id, GO_TO, { 'playerid' => player_id, 'to' => to })
  json = invoke_api(request)
  KodiResponse.new(json)
end

#move(player_id, direction = Types::Global::Direction::UP, kodi_id = 1) ⇒ Object



98
99
100
101
102
# File 'lib/kodi_client/methods/player.rb', line 98

def move(player_id, direction = Types::Global::Direction::UP, kodi_id = 1)
  request = KodiRequest.new(kodi_id, MOVE, { 'playerid' => player_id, 'direction' => direction })
  json = invoke_api(request)
  KodiResponse.new(json)
end

#play_pause(player_id, play = Types::Global::Toggle::TOGGLE, kodi_id = 1) ⇒ Object



110
111
112
113
114
115
116
# File 'lib/kodi_client/methods/player.rb', line 110

def play_pause(player_id, play = Types::Global::Toggle::TOGGLE, kodi_id = 1)
  request = KodiRequest.new(kodi_id, PLAY_PAUSE, { 'playerid' => player_id, 'play' => play })
  json = invoke_api(request)
  result = json['result']['speed']
  json['result'] = result
  KodiResponse.new(json)
end

#player_open(file, options = {}, kodi_id = 1) ⇒ Object

local file or stream url



45
46
47
48
49
# File 'lib/kodi_client/methods/player.rb', line 45

def player_open(file, options = {}, kodi_id = 1)
  request = KodiRequest.new(kodi_id, OPEN, { 'item' => { 'file' => file }, 'options' => options })
  json = invoke_api(request)
  KodiResponse.new(json)
end

#rotate(player_id, rotate = Types::Global::Rotate::CLOCKWISE, kodi_id = 1) ⇒ Object



104
105
106
107
108
# File 'lib/kodi_client/methods/player.rb', line 104

def rotate(player_id, rotate = Types::Global::Rotate::CLOCKWISE, kodi_id = 1)
  request = KodiRequest.new(kodi_id, ROTATE, { 'playerid' => player_id, 'value' => rotate })
  json = invoke_api(request)
  KodiResponse.new(json)
end

#seek(player_id, value, kodi_id = 1) ⇒ Object

seeks to the given position

return [KodiResponse] - return percentage, time and total time

Parameters:

  • player_id (Integer)
    • the player id

  • value (Float/PlayerPositionTime/PlayerSeekJump/Integer)
    • the seek value in either Percentage,

    PositionTime, Jump or seek by seconds



125
126
127
128
129
130
131
# File 'lib/kodi_client/methods/player.rb', line 125

def seek(player_id, value, kodi_id = 1)
  request = KodiRequest.new(kodi_id, SEEK, { 'playerid' => player_id, 'value' => value })
  json = invoke_api(request)
  result = Types::Player::SeekReturned.create(json['result'])
  json['result'] = result
  KodiResponse.new(json)
end

#set_audio_stream(player_id, stream, kodi_id = 1) ⇒ Object

sets the given audio stream

return [KodiResponse] ‘OK’ or error

Parameters:

  • stream (Integer, Next/Prev)
    • the stream to set, can either be the index or next/prev



138
139
140
141
142
# File 'lib/kodi_client/methods/player.rb', line 138

def set_audio_stream(player_id, stream, kodi_id = 1)
  request = KodiRequest.new(kodi_id, SET_AUDIO_STREAM, { 'playerid' => player_id, 'stream' => stream })
  json = invoke_api(request)
  KodiResponse.new(json)
end

#set_party_mode(player_id, mode = Types::Global::Toggle::TOGGLE, kodi_id = 1) ⇒ Object



144
145
146
147
148
# File 'lib/kodi_client/methods/player.rb', line 144

def set_party_mode(player_id, mode = Types::Global::Toggle::TOGGLE, kodi_id = 1)
  request = KodiRequest.new(kodi_id, SET_PARTY_MODE, { 'playerid' => player_id, 'partymode' => mode })
  json = invoke_api(request)
  KodiResponse.new(json)
end

#set_repeat(player_id, repeat = Types::Player::PlayerRepeat::ALL, kodi_id = 1) ⇒ Object



150
151
152
153
154
# File 'lib/kodi_client/methods/player.rb', line 150

def set_repeat(player_id, repeat = Types::Player::PlayerRepeat::ALL, kodi_id = 1)
  request = KodiRequest.new(kodi_id, SET_REPEAT, { 'playerid' => player_id, 'repeat' => repeat })
  json = invoke_api(request)
  KodiResponse.new(json)
end

#set_speed(player_id, speed = Types::Global::IncrementDecrement::INCREMENT, kodi_id = 1) ⇒ Object



156
157
158
159
160
161
162
# File 'lib/kodi_client/methods/player.rb', line 156

def set_speed(player_id, speed = Types::Global::IncrementDecrement::INCREMENT, kodi_id = 1)
  request = KodiRequest.new(kodi_id, SET_SPEED, { 'playerid' => player_id, 'speed' => speed })
  json = invoke_api(request)
  result = json['result']['speed']
  json['result'] = result
  KodiResponse.new(json)
end

#set_subtitle(player_id, subtitle = Types::Global::NextPrev::NEXT, enabled = false, kodi_id = 1) ⇒ KodiResponse

sets the subtitle

Parameters:

  • player_id (Integer)
    • the player id

  • subtitle (Next|Prev/Integer) (defaults to: Types::Global::NextPrev::NEXT)
    • the subtitle to set. Can either be an index or next/prev

  • enabled (Boolean) (defaults to: false)
    • true if the set subtitle should be enabled, else false

Returns:



171
172
173
174
175
176
# File 'lib/kodi_client/methods/player.rb', line 171

def set_subtitle(player_id, subtitle = Types::Global::NextPrev::NEXT, enabled = false, kodi_id = 1)
  request = KodiRequest.new(kodi_id, SET_SUBTITLE, { 'playerid' => player_id, 'subtitle' => subtitle,
                                                     'enabled' => enabled })
  json = invoke_api(request)
  KodiResponse.new(json)
end

#set_video_stream(player_id, stream = Types::Global::NextPrev::NEXT, kodi_id = 1) ⇒ KodiResponse

Sets the video stream

Parameters:

  • player_id (Integer)
    • the player id

  • stream (Next|Prev/Integer) (defaults to: Types::Global::NextPrev::NEXT)
    • the stream to set. Can either be an index or next/prev

Returns:



184
185
186
187
188
# File 'lib/kodi_client/methods/player.rb', line 184

def set_video_stream(player_id, stream = Types::Global::NextPrev::NEXT, kodi_id = 1)
  request = KodiRequest.new(kodi_id, SET_VIDEO_STREAM, { 'playerid' => player_id, 'stream' => stream })
  json = invoke_api(request)
  KodiResponse.new(json)
end

#set_view_mode(player_id, mode = Types::Player::ViewMode::NORMAL, kodi_id = 1) ⇒ Object



190
191
192
193
194
# File 'lib/kodi_client/methods/player.rb', line 190

def set_view_mode(player_id, mode = Types::Player::ViewMode::NORMAL, kodi_id = 1)
  request = KodiRequest.new(kodi_id, SET_VIEW_MODE, { 'playerid' => player_id, 'viewmode' => mode })
  json = invoke_api(request)
  KodiResponse.new(json)
end

#stop(player_id, kodi_id = 1) ⇒ Object



196
197
198
199
200
# File 'lib/kodi_client/methods/player.rb', line 196

def stop(player_id, kodi_id = 1)
  request = KodiRequest.new(kodi_id, STOP, { 'playerid' => player_id })
  json = invoke_api(request)
  KodiResponse.new(json)
end

#zoom(player_id, zoom, kodi_id = 1) ⇒ KodiResponse

Sets the zoom

Parameters:

  • player_id (Integer)
    • the player id

  • zoom (Zoom/Integer)
    • Can either be 1-10 or step In/Out

Returns:



208
209
210
211
212
# File 'lib/kodi_client/methods/player.rb', line 208

def zoom(player_id, zoom, kodi_id = 1)
  request = KodiRequest.new(kodi_id, ZOOM, { 'playerid' => player_id, 'zoom' => zoom })
  json = invoke_api(request)
  KodiResponse.new(json)
end