Able to do a demo stream, not via jni but with android's media player. Need to integrate sqlite to save token, username, password, and uri
This commit is contained in:
@@ -59,17 +59,29 @@ set (CURL_LIBRARY
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/3rdparty/android/${ANDROID_ABI}
|
||||
)
|
||||
|
||||
set (BASS_LIBRARY
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/3rdparty/bass/${ANDROID_ABI}
|
||||
)
|
||||
|
||||
set (CURL_INCLUDE_DIR
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/3rdparty/android/include/curl
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/3rdparty/android/include
|
||||
)
|
||||
set (BASS_INCLUDE_DIR
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/3rdparty/bass/include
|
||||
)
|
||||
|
||||
add_library(boo STATIC IMPORTED)
|
||||
#add_library(bass SHARED IMPORTED)
|
||||
|
||||
set_target_properties(boo PROPERTIES IMPORTED_LOCATION
|
||||
"${CMAKE_CURRENT_SOURCE_DIR}/3rdparty/android/${ANDROID_ABI}/libcurl.a"
|
||||
)
|
||||
#set_target_properties(bass PROPERTIES IMPORTED_LOCATION
|
||||
# "${CMAKE_CURRENT_SOURCE_DIR}/3rdparty/bass/${ANDROID_ABI}/libbass.so"
|
||||
# )
|
||||
|
||||
include_directories(${CURL_INCLUDE_DIR})
|
||||
include_directories(${CURL_INCLUDE_DIR}) #${BASS_INCLUDE_DIR})
|
||||
|
||||
# Specifies libraries CMake should link to your target library. You
|
||||
# can link multiple libraries, such as libraries you define in this
|
||||
@@ -79,6 +91,7 @@ target_link_libraries(native-lib PRIVATE
|
||||
|
||||
nlohmann_json::nlohmann_json
|
||||
boo
|
||||
#bass
|
||||
${log-lib}
|
||||
z
|
||||
)
|
||||
@@ -3,6 +3,7 @@
|
||||
//
|
||||
|
||||
#include <iostream>
|
||||
#include <filesystem>
|
||||
#include <cstring>
|
||||
#include <jni.h>
|
||||
#include <string>
|
||||
@@ -15,7 +16,7 @@
|
||||
#include <android/sharedmem.h>
|
||||
#include <sys/mman.h>
|
||||
|
||||
#include "nlohmann/json.hpp"
|
||||
#include <nlohmann/json.hpp>
|
||||
#include <curl/curl.h>
|
||||
|
||||
#include "model/Song.h"
|
||||
@@ -24,16 +25,16 @@
|
||||
#include "Tok.h"
|
||||
|
||||
|
||||
model::Song retrieveSong(const std::string&);
|
||||
model::Song retrieveSong(const std::string&, const std::string&);
|
||||
|
||||
std::string fetchToken(const std::string&, const std::string&, const std::string&);
|
||||
|
||||
|
||||
model::Song retrieveSong(const std::string& token)
|
||||
model::Song retrieveSong(const std::string& token, const std::string& baseUri)
|
||||
{
|
||||
repository::SongRepository songRepo;
|
||||
model::Song song;
|
||||
song.id = 2;
|
||||
song.id = 1;
|
||||
song.title = "Smooth";
|
||||
song.album = "Amaze";
|
||||
song.artist = "The Herb";
|
||||
@@ -41,7 +42,7 @@ model::Song retrieveSong(const std::string& token)
|
||||
song.duration = 420;
|
||||
song.year = 420;
|
||||
|
||||
song = songRepo.retrieveSong(token, song.id);
|
||||
song = songRepo.retrieveSong(token, baseUri, song);
|
||||
|
||||
return song;
|
||||
}
|
||||
@@ -60,6 +61,22 @@ std::string fetchToken(const std::string& username, const std::string& password,
|
||||
}
|
||||
|
||||
|
||||
void iterateDirectory(const std::string& path)
|
||||
{
|
||||
/**
|
||||
auto somePath = std::filesystem::path(path);
|
||||
for (auto dir: std::filesystem::directory_iterator(somePath)) {
|
||||
auto foundPath = dir;
|
||||
if (foundPath.is_directory()) {
|
||||
auto dirPath = foundPath.path();
|
||||
} else {
|
||||
auto filePath = foundPath.path();
|
||||
}
|
||||
}
|
||||
*/
|
||||
}
|
||||
|
||||
|
||||
extern "C"
|
||||
JNIEXPORT jstring
|
||||
JNICALL
|
||||
@@ -86,13 +103,13 @@ JNICALL
|
||||
Java_com_example_mear_activities_DemoStreamActivity_retrieveSong(
|
||||
JNIEnv *env,
|
||||
jobject thisObj,
|
||||
jstring token
|
||||
jstring token,
|
||||
jstring apiUri
|
||||
)
|
||||
{
|
||||
const std::string tok = env->GetStringUTFChars(token, NULL);
|
||||
|
||||
auto song = retrieveSong(tok);
|
||||
std::string bank = "SBI Bank";
|
||||
const std::string baseUri = env->GetStringUTFChars(apiUri, NULL);
|
||||
auto song = retrieveSong(tok, baseUri);
|
||||
|
||||
jclass songClass = env->FindClass( "com/example/mear/models/Song");
|
||||
jmethodID jconstructor = env->GetMethodID( songClass, "<init>", "()V" );
|
||||
@@ -124,3 +141,18 @@ Java_com_example_mear_activities_DemoStreamActivity_retrieveSong(
|
||||
|
||||
return songObj;
|
||||
}
|
||||
|
||||
|
||||
|
||||
extern "C"
|
||||
JNIEXPORT void
|
||||
JNICALL
|
||||
Java_com_example_mear_activities_DemoStreamActivity_pathIteratorDemo(
|
||||
JNIEnv *env,
|
||||
jobject thisObj,
|
||||
jstring path
|
||||
) {
|
||||
|
||||
const std::string pathStr = env->GetStringUTFChars(path, NULL);
|
||||
iterateDirectory(pathStr);
|
||||
}
|
||||
|
||||
@@ -19,7 +19,7 @@ namespace repository {
|
||||
|
||||
|
||||
model::Song SongRepository::retrieveSong(const std::string& token, const int id) {
|
||||
std::string uri;
|
||||
std::string uri("");
|
||||
uri.append(std::to_string(id));
|
||||
model::Song song;
|
||||
|
||||
@@ -63,6 +63,100 @@ namespace repository {
|
||||
return song;
|
||||
}
|
||||
|
||||
model::Song SongRepository::retrieveSong(const std::string& token, const std::string& baseUri,
|
||||
const int id) {
|
||||
std::string uri(baseUri);
|
||||
uri.append("/api/v1/song/");
|
||||
uri.append(std::to_string(id));
|
||||
model::Song song;
|
||||
|
||||
CURL *curl;
|
||||
CURLcode res;
|
||||
struct curl_slist *chunk = NULL;
|
||||
curl = curl_easy_init();
|
||||
|
||||
if (!curl) {
|
||||
return song;
|
||||
}
|
||||
|
||||
auto resp = std::make_unique<char[]>(10000);
|
||||
|
||||
std::string authInfo("Authorization: Bearer ");
|
||||
authInfo.append(token);
|
||||
chunk = curl_slist_append(chunk, authInfo.c_str());
|
||||
|
||||
curl_easy_setopt(curl, CURLOPT_URL, uri.c_str());
|
||||
curl_easy_setopt(curl, CURLOPT_HTTPHEADER, chunk);
|
||||
curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, respBodyRetriever);
|
||||
curl_easy_setopt(curl, CURLOPT_WRITEDATA, resp.get());
|
||||
curl_easy_setopt(curl, CURLOPT_SSL_VERIFYPEER, 0L);
|
||||
|
||||
res = curl_easy_perform(curl);
|
||||
curl_easy_cleanup(curl);
|
||||
|
||||
if (res == CURLE_OK) {
|
||||
auto s = nlohmann::json::parse(resp.get());
|
||||
song.id = s["id"].get<int>();
|
||||
song.title = s["title"].get<std::string>();
|
||||
song.album = s["album"].get<std::string>();
|
||||
song.artist = s["artist"].get<std::string>();
|
||||
song.genre = s["genre"].get<std::string>();
|
||||
song.duration = s["duration"].get<int>();
|
||||
song.year = s["year"].get<int>();
|
||||
|
||||
return song;
|
||||
}
|
||||
|
||||
return song;
|
||||
}
|
||||
|
||||
model::Song SongRepository::retrieveSong(const std::string& token, const std::string& baseUri,
|
||||
const model::Song& sng) {
|
||||
std::string uri(baseUri);
|
||||
uri.append("/api/v1/song/");
|
||||
uri.append(std::to_string(sng.id));
|
||||
model::Song song;
|
||||
|
||||
CURL *curl;
|
||||
CURLcode res;
|
||||
struct curl_slist *chunk = NULL;
|
||||
curl = curl_easy_init();
|
||||
|
||||
if (!curl) {
|
||||
return sng;
|
||||
}
|
||||
|
||||
auto resp = std::make_unique<char[]>(10000);
|
||||
|
||||
std::string authInfo("Authorization: Bearer ");
|
||||
authInfo.append(token);
|
||||
chunk = curl_slist_append(chunk, authInfo.c_str());
|
||||
|
||||
curl_easy_setopt(curl, CURLOPT_URL, uri.c_str());
|
||||
curl_easy_setopt(curl, CURLOPT_HTTPHEADER, chunk);
|
||||
curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, respBodyRetriever);
|
||||
curl_easy_setopt(curl, CURLOPT_WRITEDATA, resp.get());
|
||||
curl_easy_setopt(curl, CURLOPT_SSL_VERIFYPEER, 0L);
|
||||
|
||||
res = curl_easy_perform(curl);
|
||||
curl_easy_cleanup(curl);
|
||||
|
||||
if (res == CURLE_OK) {
|
||||
auto s = nlohmann::json::parse(resp.get());
|
||||
song.id = s["id"].get<int>();
|
||||
song.title = s["title"].get<std::string>();
|
||||
song.album = s["album"].get<std::string>();
|
||||
song.artist = s["artist"].get<std::string>();
|
||||
song.genre = s["genre"].get<std::string>();
|
||||
song.duration = s["duration"].get<int>();
|
||||
song.year = s["year"].get<int>();
|
||||
|
||||
return song;
|
||||
}
|
||||
|
||||
return sng;
|
||||
}
|
||||
|
||||
|
||||
size_t SongRepository::respBodyRetriever(void* ptr, size_t size, size_t nmemb, char *e)
|
||||
{
|
||||
|
||||
@@ -17,6 +17,8 @@ namespace repository {
|
||||
std::vector<model::Song> fetchSongs(const std::string&, const std::string&);
|
||||
|
||||
model::Song retrieveSong(const std::string&, const int);
|
||||
model::Song retrieveSong(const std::string&, const std::string&, const int);
|
||||
model::Song retrieveSong(const std::string&, const std::string&, const model::Song&);
|
||||
private:
|
||||
static size_t respBodyRetriever(void*, size_t, size_t, char*);
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user