[Windows] Remove redundant DirectSound error codes
[xbmc.git] / xbmc / platform / android / activity / JNIXBMCMediaSession.cpp
blobf8cea2c4cf504107a0f178b1534f86702a88348f
1 /*
2 * Copyright (C) 2017 Christian Browet
3 * This file is part of Kodi - https://kodi.tv
5 * SPDX-License-Identifier: GPL-2.0-or-later
6 * See LICENSES/README.md for more information.
7 */
9 #include "JNIXBMCMediaSession.h"
11 #include "AndroidKey.h"
12 #include "CompileInfo.h"
13 #include "ServiceBroker.h"
14 #include "XBMCApp.h"
15 #include "application/Application.h"
16 #include "application/ApplicationComponents.h"
17 #include "application/ApplicationPlayer.h"
18 #include "input/actions/Action.h"
19 #include "input/actions/ActionIDs.h"
20 #include "messaging/ApplicationMessenger.h"
22 #include <androidjni/Context.h>
23 #include <androidjni/KeyEvent.h>
24 #include <androidjni/jutils-details.hpp>
26 using namespace jni;
28 static std::string s_className = std::string(CCompileInfo::GetClass()) + "/XBMCMediaSession";
30 CJNIXBMCMediaSession::CJNIXBMCMediaSession()
31 : CJNIBase(s_className)
33 m_object = new_object(CJNIContext::getClassLoader().loadClass(GetDotClassName(s_className)));
34 m_object.setGlobal();
36 add_instance(m_object, this);
39 CJNIXBMCMediaSession::CJNIXBMCMediaSession(const CJNIXBMCMediaSession& other)
40 : CJNIBase(other)
42 add_instance(m_object, this);
45 CJNIXBMCMediaSession::~CJNIXBMCMediaSession()
47 remove_instance(this);
50 void CJNIXBMCMediaSession::RegisterNatives(JNIEnv* env)
52 jclass cClass = env->FindClass(s_className.c_str());
53 if(cClass)
55 JNINativeMethod methods[] =
57 {"_onPlayRequested", "()V", (void*)&CJNIXBMCMediaSession::_onPlayRequested},
58 {"_onPauseRequested", "()V", (void*)&CJNIXBMCMediaSession::_onPauseRequested},
59 {"_onNextRequested", "()V", (void*)&CJNIXBMCMediaSession::_onNextRequested},
60 {"_onPreviousRequested", "()V", (void*)&CJNIXBMCMediaSession::_onPreviousRequested},
61 {"_onForwardRequested", "()V", (void*)&CJNIXBMCMediaSession::_onForwardRequested},
62 {"_onRewindRequested", "()V", (void*)&CJNIXBMCMediaSession::_onRewindRequested},
63 {"_onStopRequested", "()V", (void*)&CJNIXBMCMediaSession::_onStopRequested},
64 {"_onSeekRequested", "(J)V", (void*)&CJNIXBMCMediaSession::_onSeekRequested},
65 {"_onMediaButtonEvent", "(Landroid/content/Intent;)Z", (void*)&CJNIXBMCMediaSession::_onMediaButtonEvent},
68 env->RegisterNatives(cClass, methods, sizeof(methods)/sizeof(methods[0]));
72 void CJNIXBMCMediaSession::activate(bool state)
74 if (state == m_isActive)
75 return;
77 call_method<void>(m_object,
78 "activate", "(Z)V",
79 (jboolean)state);
80 m_isActive = state;
83 void CJNIXBMCMediaSession::updatePlaybackState(const CJNIPlaybackState& state)
85 call_method<void>(m_object,
86 "updatePlaybackState", "(Landroid/media/session/PlaybackState;)V",
87 state.get_raw());
90 void CJNIXBMCMediaSession::updateMetadata(const CJNIMediaMetadata& myData)
92 call_method<void>(m_object,
93 "updateMetadata", "(Landroid/media/MediaMetadata;)V",
94 myData.get_raw());
97 void CJNIXBMCMediaSession::updateIntent(const CJNIIntent& intent)
99 call_method<void>(m_object,
100 "updateIntent", "(Landroid/content/Intent;)V",
101 intent.get_raw());
104 void CJNIXBMCMediaSession::OnPlayRequested()
106 const auto& components = CServiceBroker::GetAppComponents();
107 const auto appPlayer = components.GetComponent<CApplicationPlayer>();
108 if (appPlayer->IsPlaying())
110 if (appPlayer->IsPaused())
111 CServiceBroker::GetAppMessenger()->PostMsg(TMSG_GUI_ACTION, WINDOW_INVALID, -1,
112 static_cast<void*>(new CAction(ACTION_PAUSE)));
116 void CJNIXBMCMediaSession::OnPauseRequested()
118 const auto& components = CServiceBroker::GetAppComponents();
119 const auto appPlayer = components.GetComponent<CApplicationPlayer>();
120 if (appPlayer->IsPlaying())
122 if (!appPlayer->IsPaused())
123 CServiceBroker::GetAppMessenger()->PostMsg(TMSG_GUI_ACTION, WINDOW_INVALID, -1,
124 static_cast<void*>(new CAction(ACTION_PAUSE)));
128 void CJNIXBMCMediaSession::OnNextRequested()
130 const auto& components = CServiceBroker::GetAppComponents();
131 const auto appPlayer = components.GetComponent<CApplicationPlayer>();
132 if (appPlayer->IsPlaying())
133 CServiceBroker::GetAppMessenger()->PostMsg(TMSG_GUI_ACTION, WINDOW_INVALID, -1,
134 static_cast<void*>(new CAction(ACTION_NEXT_ITEM)));
137 void CJNIXBMCMediaSession::OnPreviousRequested()
139 const auto& components = CServiceBroker::GetAppComponents();
140 const auto appPlayer = components.GetComponent<CApplicationPlayer>();
141 if (appPlayer->IsPlaying())
142 CServiceBroker::GetAppMessenger()->PostMsg(TMSG_GUI_ACTION, WINDOW_INVALID, -1,
143 static_cast<void*>(new CAction(ACTION_PREV_ITEM)));
146 void CJNIXBMCMediaSession::OnForwardRequested()
148 const auto& components = CServiceBroker::GetAppComponents();
149 const auto appPlayer = components.GetComponent<CApplicationPlayer>();
150 if (appPlayer->IsPlaying())
152 if (!appPlayer->IsPaused())
153 CServiceBroker::GetAppMessenger()->PostMsg(
154 TMSG_GUI_ACTION, WINDOW_INVALID, -1,
155 static_cast<void*>(new CAction(ACTION_PLAYER_FORWARD)));
159 void CJNIXBMCMediaSession::OnRewindRequested()
161 const auto& components = CServiceBroker::GetAppComponents();
162 const auto appPlayer = components.GetComponent<CApplicationPlayer>();
163 if (appPlayer->IsPlaying())
165 if (!appPlayer->IsPaused())
166 CServiceBroker::GetAppMessenger()->PostMsg(
167 TMSG_GUI_ACTION, WINDOW_INVALID, -1,
168 static_cast<void*>(new CAction(ACTION_PLAYER_REWIND)));
172 void CJNIXBMCMediaSession::OnStopRequested()
174 const auto& components = CServiceBroker::GetAppComponents();
175 const auto appPlayer = components.GetComponent<CApplicationPlayer>();
176 if (appPlayer->IsPlaying())
177 CServiceBroker::GetAppMessenger()->PostMsg(TMSG_GUI_ACTION, WINDOW_INVALID, -1,
178 static_cast<void*>(new CAction(ACTION_STOP)));
181 void CJNIXBMCMediaSession::OnSeekRequested(int64_t pos)
183 g_application.SeekTime(pos / 1000.0);
186 bool CJNIXBMCMediaSession::OnMediaButtonEvent(const CJNIIntent& intent)
188 if (CXBMCApp::Get().HasFocus())
190 CXBMCApp::Get().onReceive(intent);
191 return true;
193 return false;
196 bool CJNIXBMCMediaSession::isActive() const
198 return m_isActive;
201 /**********************/
203 void CJNIXBMCMediaSession::_onPlayRequested(JNIEnv* env, jobject thiz)
205 (void)env;
207 CJNIXBMCMediaSession *inst = find_instance(thiz);
208 if (inst)
209 inst->OnPlayRequested();
212 void CJNIXBMCMediaSession::_onPauseRequested(JNIEnv* env, jobject thiz)
214 (void)env;
216 CJNIXBMCMediaSession *inst = find_instance(thiz);
217 if (inst)
218 inst->OnPauseRequested();
221 void CJNIXBMCMediaSession::_onNextRequested(JNIEnv* env, jobject thiz)
223 (void)env;
225 CJNIXBMCMediaSession *inst = find_instance(thiz);
226 if (inst)
227 inst->OnNextRequested();
230 void CJNIXBMCMediaSession::_onPreviousRequested(JNIEnv* env, jobject thiz)
232 (void)env;
234 CJNIXBMCMediaSession *inst = find_instance(thiz);
235 if (inst)
236 inst->OnPreviousRequested();
239 void CJNIXBMCMediaSession::_onForwardRequested(JNIEnv* env, jobject thiz)
241 (void)env;
243 CJNIXBMCMediaSession *inst = find_instance(thiz);
244 if (inst)
245 inst->OnForwardRequested();
248 void CJNIXBMCMediaSession::_onRewindRequested(JNIEnv* env, jobject thiz)
250 (void)env;
252 CJNIXBMCMediaSession *inst = find_instance(thiz);
253 if (inst)
254 inst->OnRewindRequested();
257 void CJNIXBMCMediaSession::_onStopRequested(JNIEnv* env, jobject thiz)
259 (void)env;
261 CJNIXBMCMediaSession *inst = find_instance(thiz);
262 if (inst)
263 inst->OnStopRequested();
266 void CJNIXBMCMediaSession::_onSeekRequested(JNIEnv* env, jobject thiz, jlong pos)
268 (void)env;
270 CJNIXBMCMediaSession *inst = find_instance(thiz);
271 if (inst)
272 inst->OnSeekRequested(pos);
275 bool CJNIXBMCMediaSession::_onMediaButtonEvent(JNIEnv* env, jobject thiz, jobject intent)
277 (void)env;
279 CJNIXBMCMediaSession *inst = find_instance(thiz);
280 if (inst)
281 return inst->OnMediaButtonEvent(CJNIIntent(jhobject::fromJNI(intent)));
282 return false;