diff --git a/.idea/caches/build_file_checksums.ser b/.idea/caches/build_file_checksums.ser
index 5ad0101..c7fb425 100644
Binary files a/.idea/caches/build_file_checksums.ser and b/.idea/caches/build_file_checksums.ser differ
diff --git a/.idea/workspace.xml b/.idea/workspace.xml
index 7639c24..e5f17fb 100644
--- a/.idea/workspace.xml
+++ b/.idea/workspace.xml
@@ -109,82 +109,7 @@
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
@@ -192,11 +117,9 @@
-
-
+
-
@@ -265,98 +188,137 @@
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
@@ -378,16 +345,17 @@
-
-
+
+
-
+
+
@@ -399,104 +367,29 @@
-
+
-
+
+
+
+
-
-
+
+
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
+
+
-
-
-
@@ -600,6 +493,14 @@
1564017463922
+
+ 1570311037655
+
+
+
+ 1570311037656
+
+
@@ -607,12 +508,12 @@
-
+
-
+
@@ -621,7 +522,7 @@
-
+
@@ -632,45 +533,36 @@
+
+
+
+
- file://$PROJECT_DIR$/app/src/main/java/com/example/mear/activities/DemoStreamActivity.kt
- 62
+ file://$PROJECT_DIR$/app/src/main/java/com/example/mear/playback/service/MusicService.kt
+ 130
-
+
file://$PROJECT_DIR$/app/src/main/java/com/example/mear/activities/DemoStreamActivity.kt
- 60
+ 76
-
+
-
- file://$PROJECT_DIR$/app/src/main/cpp/Demo.cpp
- 139
-
+
+ file://$PROJECT_DIR$/app/src/main/java/com/example/mear/activities/DemoStreamActivity.kt
+ 68
+
+
-
- file://$PROJECT_DIR$/app/src/main/cpp/Demo.cpp
- 98
-
-
-
- file://$PROJECT_DIR$/app/src/main/cpp/Demo.cpp
- 126
-
-
-
- file://$PROJECT_DIR$/app/src/main/cpp/SongRepository.cpp
- 47
-
-
-
- file://$PROJECT_DIR$/app/src/main/cpp/Demo.cpp
- 33
-
+
+ file://$PROJECT_DIR$/app/src/main/java/com/example/mear/activities/DemoStreamActivity.kt
+ 71
+
+
@@ -684,16 +576,6 @@
-
-
-
-
-
-
-
-
-
-
@@ -736,18 +618,6 @@
-
-
-
-
-
-
-
-
-
-
-
-
@@ -755,13 +625,6 @@
-
-
-
-
-
-
-
@@ -776,12 +639,110 @@
-
+
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
-
+
+
+
+
+
+
+
+
+
+
+
@@ -789,37 +750,101 @@
-
+
-
+
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
-
-
+
+
+
+
+
+
+
+
+
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
-
-
-
-
-
+
+
diff --git a/app/src/main/cpp/CMakeLists.txt b/app/src/main/cpp/CMakeLists.txt
index 4e5ed9d..b93950c 100644
--- a/app/src/main/cpp/CMakeLists.txt
+++ b/app/src/main/cpp/CMakeLists.txt
@@ -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
)
\ No newline at end of file
diff --git a/app/src/main/cpp/Demo.cpp b/app/src/main/cpp/Demo.cpp
index c0064e5..cb924e9 100644
--- a/app/src/main/cpp/Demo.cpp
+++ b/app/src/main/cpp/Demo.cpp
@@ -3,6 +3,7 @@
//
#include
+#include
#include
#include
#include
@@ -15,7 +16,7 @@
#include
#include
-#include "nlohmann/json.hpp"
+#include
#include
#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, "", "()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);
+}
diff --git a/app/src/main/cpp/SongRepository.cpp b/app/src/main/cpp/SongRepository.cpp
index d44e17f..757a54c 100644
--- a/app/src/main/cpp/SongRepository.cpp
+++ b/app/src/main/cpp/SongRepository.cpp
@@ -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(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();
+ song.title = s["title"].get();
+ song.album = s["album"].get();
+ song.artist = s["artist"].get();
+ song.genre = s["genre"].get();
+ song.duration = s["duration"].get();
+ song.year = s["year"].get();
+
+ 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(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();
+ song.title = s["title"].get();
+ song.album = s["album"].get();
+ song.artist = s["artist"].get();
+ song.genre = s["genre"].get();
+ song.duration = s["duration"].get();
+ song.year = s["year"].get();
+
+ return song;
+ }
+
+ return sng;
+ }
+
size_t SongRepository::respBodyRetriever(void* ptr, size_t size, size_t nmemb, char *e)
{
diff --git a/app/src/main/cpp/SongRepository.h b/app/src/main/cpp/SongRepository.h
index 5808622..603c1f6 100644
--- a/app/src/main/cpp/SongRepository.h
+++ b/app/src/main/cpp/SongRepository.h
@@ -17,6 +17,8 @@ namespace repository {
std::vector 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*);
};
diff --git a/app/src/main/java/com/example/mear/activities/DemoStreamActivity.kt b/app/src/main/java/com/example/mear/activities/DemoStreamActivity.kt
index f32a864..9120f4d 100644
--- a/app/src/main/java/com/example/mear/activities/DemoStreamActivity.kt
+++ b/app/src/main/java/com/example/mear/activities/DemoStreamActivity.kt
@@ -1,6 +1,7 @@
package com.example.mear.activities
import android.os.Bundle
+import android.os.Environment
import android.support.design.widget.Snackbar
import android.support.v7.app.AppCompatActivity
import com.example.mear.R
@@ -11,7 +12,7 @@ import org.jetbrains.anko.toast
import com.example.mear.models.Song
-class DemoStreamActivity : AppCompatActivity() {
+class DemoStreamActivity : BaseServiceActivity() {
companion object {
init {
@@ -24,7 +25,9 @@ class DemoStreamActivity : AppCompatActivity() {
private external fun logUser(usr: String, pass: String, api: String): String
- private external fun retrieveSong(tok: String): Song
+ private external fun retrieveSong(tok: String, api: String): Song
+ //private external fun testSongStream(tok: String, id: Int)
+ private external fun pathIteratorDemo(path: String)
override fun onCreate(savedInstanceState: Bundle?) {
@@ -32,6 +35,8 @@ class DemoStreamActivity : AppCompatActivity() {
setContentView(R.layout.activity_demo_stream)
setSupportActionBar(toolbar)
+ doBindService()
+
demoStream.setOnClickListener {
toast("vacant").show()
}
@@ -57,8 +62,20 @@ class DemoStreamActivity : AppCompatActivity() {
var apiUriStr = apiUri.text.toString()
token = logUser(usernameStr, passwordStr, apiUriStr)
- toast(token!!).show()
- var s = retrieveSong(token!!);
+
+ try {
+
+ var s = retrieveSong(token!!, apiUriStr)
+ musicService!!.icarusPlaySong(this.applicationContext, token!!, apiUriStr, s)
+ val dir = Environment.getExternalStorageDirectory().absolutePath + "/music"
+ pathIteratorDemo(dir)
+ var currentTrack = musicService!!.getCurrentTrack()
+ val title = currentTrack.title
+ val artist = currentTrack.artist
+ }
+ catch (ex: Exception) {
+ val msg = ex.message
+ }
}
private fun validFields(): Boolean {
diff --git a/app/src/main/java/com/example/mear/playback/service/MusicService.kt b/app/src/main/java/com/example/mear/playback/service/MusicService.kt
index b993feb..d49116f 100644
--- a/app/src/main/java/com/example/mear/playback/service/MusicService.kt
+++ b/app/src/main/java/com/example/mear/playback/service/MusicService.kt
@@ -1,8 +1,10 @@
package com.example.mear.playback.service
import android.app.Service
+import android.content.Context
import android.content.Intent
import android.media.MediaPlayer
+import android.net.Uri
import android.os.Binder
import android.os.Environment
import android.os.IBinder
@@ -16,6 +18,7 @@ import com.example.mear.constants.Interval
import com.example.mear.management.MusicFiles
import com.example.mear.management.TrackManager
import com.example.mear.models.PlayControls
+import com.example.mear.models.Song
import com.example.mear.models.Track
import com.example.mear.repositories.RepeatRepository
import com.example.mear.repositories.ShuffleRepository
@@ -90,6 +93,46 @@ class MusicService: Service() {
}
}
+ fun icarusPlaySong(token: String, song: Song) {
+ var uriBase = "https://www.soaricarus.com/api/v1/song/stream/"
+ val id = song.id
+ uriBase += "$id"
+ var uri: Uri = Uri.parse(uriBase)
+ var hddr: MutableMap = mutableMapOf()
+ hddr["Authorization"] = "Bearer $token"
+ try {
+ trackPlayer!!.reset()
+ trackPlayer!!.setDataSource(this, uri, hddr)
+ trackPlayer!!.prepare()
+ trackPlayer!!.start()
+ }
+ catch (ex: Exception) {
+ val msg = ex.message
+ }
+ }
+
+ fun icarusPlaySong(ctx: Context, token: String, uriBase: String, song: Song) {
+ var uriStr = uriBase
+ val id = song.id
+ uriStr += "/api/v1/song/stream/"
+ uriStr += "$id"
+
+ var uri: Uri = Uri.parse(uriStr)
+ var hddr: MutableMap = mutableMapOf()
+ hddr["Authorization"] = "Bearer $token"
+
+ try {
+ trackPlayer!!.reset()
+ trackPlayer!!.setDataSource(ctx, uri, hddr)
+ trackPlayer!!.prepare()
+ trackPlayer!!.start()
+ }
+ catch (ex: Exception) {
+ val msg = ex.message
+ }
+ }
+
+
fun goToPosition(progress: Int) {
trackPlayer!!.seekTo(progress)
}