Merge branch 'develop' into write-pid-before-exit
20
.clang-format
Normal file
|
@ -0,0 +1,20 @@
|
|||
---
|
||||
AccessModifierOffset: '-4'
|
||||
AllowShortBlocksOnASingleLine: 'false'
|
||||
AllowShortCaseLabelsOnASingleLine: 'false'
|
||||
AllowShortFunctionsOnASingleLine: None
|
||||
AllowShortIfStatementsOnASingleLine: 'false'
|
||||
AllowShortLoopsOnASingleLine: 'false'
|
||||
AlwaysBreakTemplateDeclarations: 'true'
|
||||
BreakBeforeBraces: Allman
|
||||
ColumnLimit: '160'
|
||||
IndentCaseLabels: 'true'
|
||||
IndentWidth: '4'
|
||||
Language: Cpp
|
||||
MaxEmptyLinesToKeep: '3'
|
||||
PenaltyBreakComment: '100000'
|
||||
PointerAlignment: Left
|
||||
Standard: Cpp11
|
||||
UseTab: Never
|
||||
|
||||
...
|
21
.gitignore
vendored
|
@ -34,3 +34,24 @@ server/snapserver
|
|||
GPATH
|
||||
GRTAGS
|
||||
GTAGS
|
||||
build
|
||||
bin
|
||||
android/.idea
|
||||
android/Snapcast/release
|
||||
|
||||
# debian packages
|
||||
debian/.debhelper
|
||||
debian/snapclient
|
||||
debian/snapserver
|
||||
debian/debhelper-build-stamp
|
||||
debian/snapclient.debhelper.log
|
||||
debian/snapserver.debhelper.log
|
||||
debian/files
|
||||
debian/snapclient.postinst.debhelper
|
||||
debian/snapclient.postrm.debhelper
|
||||
debian/snapclient.prerm.debhelper
|
||||
debian/snapclient.substvars
|
||||
debian/snapserver.postinst.debhelper
|
||||
debian/snapserver.postrm.debhelper
|
||||
debian/snapserver.prerm.debhelper
|
||||
debian/snapserver.substvars
|
||||
|
|
24
.gitmodules
vendored
|
@ -1,21 +1,15 @@
|
|||
[submodule "externals/popl"]
|
||||
path = externals/popl
|
||||
url = https://github.com/badaix/popl.git
|
||||
[submodule "externals/asio"]
|
||||
path = externals/asio
|
||||
url = https://github.com/chriskohlhoff/asio.git
|
||||
[submodule "externals/flac"]
|
||||
path = externals/flac
|
||||
url = https://git.xiph.org/flac.git
|
||||
url = https://gitlab.xiph.org/xiph/flac.git
|
||||
[submodule "externals/ogg"]
|
||||
path = externals/ogg
|
||||
url = https://git.xiph.org/ogg.git
|
||||
url = https://gitlab.xiph.org/xiph/ogg.git
|
||||
[submodule "externals/tremor"]
|
||||
path = externals/tremor
|
||||
url = https://git.xiph.org/tremor.git
|
||||
[submodule "externals/jsonrpcpp"]
|
||||
path = externals/jsonrpcpp
|
||||
url = https://github.com/badaix/jsonrpcpp.git
|
||||
[submodule "externals/aixlog"]
|
||||
path = externals/aixlog
|
||||
url = https://github.com/badaix/aixlog.git
|
||||
url = https://github.com/badaix/tremor.git
|
||||
[submodule "externals/opus"]
|
||||
path = externals/opus
|
||||
url = https://gitlab.xiph.org/xiph/opus.git
|
||||
[submodule "externals/oboe"]
|
||||
path = externals/oboe
|
||||
url = https://github.com/google/oboe.git
|
||||
|
|
206
.travis.yml
|
@ -1,28 +1,208 @@
|
|||
language: cpp
|
||||
compiler:
|
||||
- gcc
|
||||
dist: trusty
|
||||
sudo: required
|
||||
group: edge
|
||||
|
||||
git:
|
||||
submodules: false
|
||||
|
||||
matrix:
|
||||
include:
|
||||
# build on ubuntu
|
||||
- os: linux
|
||||
sudo: required
|
||||
compiler: gcc
|
||||
env:
|
||||
- COMPILER=g++-4.9
|
||||
addons:
|
||||
apt:
|
||||
sources:
|
||||
- sourceline: 'ppa:mhier/libboost-latest'
|
||||
- ubuntu-toolchain-r-test
|
||||
packages:
|
||||
- build-essential libasound2-dev libvorbisidec-dev libvorbis-dev libflac-dev alsa-utils libavahi-client-dev avahi-daemon
|
||||
- g++-4.9 boost1.70 libasound2-dev libsoxr-dev libvorbisidec-dev libvorbis-dev libflac-dev libopus-dev alsa-utils libavahi-client-dev avahi-daemon
|
||||
|
||||
- os: linux
|
||||
compiler: gcc
|
||||
env:
|
||||
- MATRIX_EVAL="CC=gcc-7 && CXX=g++-7"
|
||||
- COMPILER=g++-5
|
||||
addons:
|
||||
apt:
|
||||
sources:
|
||||
- sourceline: 'ppa:mhier/libboost-latest'
|
||||
- ubuntu-toolchain-r-test
|
||||
packages:
|
||||
- g++-5 boost1.70 libasound2-dev libsoxr-dev libvorbisidec-dev libvorbis-dev libflac-dev libopus-dev alsa-utils libavahi-client-dev avahi-daemon
|
||||
|
||||
- os: linux
|
||||
compiler: gcc
|
||||
env:
|
||||
- COMPILER=g++-6
|
||||
addons:
|
||||
apt:
|
||||
sources:
|
||||
- sourceline: 'ppa:mhier/libboost-latest'
|
||||
- ubuntu-toolchain-r-test
|
||||
packages:
|
||||
- g++-6 boost1.70 libasound2-dev libsoxr-dev libvorbisidec-dev libvorbis-dev libflac-dev libopus-dev alsa-utils libavahi-client-dev avahi-daemon
|
||||
|
||||
- os: linux
|
||||
compiler: gcc
|
||||
env:
|
||||
- COMPILER=g++-7
|
||||
addons:
|
||||
apt:
|
||||
sources:
|
||||
- sourceline: 'ppa:mhier/libboost-latest'
|
||||
- ubuntu-toolchain-r-test
|
||||
packages:
|
||||
- g++-7 boost1.70 libasound2-dev libsoxr-dev libvorbisidec-dev libvorbis-dev libflac-dev libopus-dev alsa-utils libavahi-client-dev avahi-daemon
|
||||
|
||||
- os: linux
|
||||
compiler: gcc
|
||||
env:
|
||||
- COMPILER=g++-8
|
||||
addons:
|
||||
apt:
|
||||
sources:
|
||||
- sourceline: 'ppa:mhier/libboost-latest'
|
||||
- ubuntu-toolchain-r-test
|
||||
packages:
|
||||
- g++-8 boost1.70 libasound2-dev libsoxr-dev libvorbisidec-dev libvorbis-dev libflac-dev libopus-dev alsa-utils libavahi-client-dev avahi-daemon
|
||||
|
||||
- os: linux
|
||||
compiler: gcc
|
||||
env:
|
||||
- COMPILER=g++-9
|
||||
addons:
|
||||
apt:
|
||||
sources:
|
||||
- sourceline: 'ppa:mhier/libboost-latest'
|
||||
- ubuntu-toolchain-r-test
|
||||
packages:
|
||||
- g++-9 boost1.70 libasound2-dev libsoxr-dev libvorbisidec-dev libvorbis-dev libflac-dev libopus-dev alsa-utils libavahi-client-dev avahi-daemon
|
||||
|
||||
|
||||
- os: linux
|
||||
compiler: clang
|
||||
env:
|
||||
- COMPILER=clang++-3.9
|
||||
- CXXFLAGS=-stdlib=libc++
|
||||
- CC=clang-3.9
|
||||
addons:
|
||||
apt:
|
||||
sources:
|
||||
- sourceline: 'ppa:mhier/libboost-latest'
|
||||
- llvm-toolchain-trusty-3.9
|
||||
packages:
|
||||
- clang-3.9 boost1.70 libasound2-dev libsoxr-dev libvorbisidec-dev libvorbis-dev libflac-dev libopus-dev alsa-utils libavahi-client-dev avahi-daemon
|
||||
|
||||
- os: linux
|
||||
compiler: clang
|
||||
env:
|
||||
- COMPILER=clang++-4.0
|
||||
- CXXFLAGS=-stdlib=libc++
|
||||
- CC=clang-4.0
|
||||
addons:
|
||||
apt:
|
||||
sources:
|
||||
- sourceline: 'ppa:mhier/libboost-latest'
|
||||
- llvm-toolchain-trusty-4.0
|
||||
packages:
|
||||
- clang-4.0 boost1.70 libasound2-dev libsoxr-dev libvorbisidec-dev libvorbis-dev libflac-dev libopus-dev alsa-utils libavahi-client-dev avahi-daemon
|
||||
|
||||
- os: linux
|
||||
compiler: clang
|
||||
env:
|
||||
- COMPILER=clang++-5.0
|
||||
- CXXFLAGS=-stdlib=libc++
|
||||
- CC=clang-5.0
|
||||
addons:
|
||||
apt:
|
||||
sources:
|
||||
- sourceline: 'ppa:mhier/libboost-latest'
|
||||
- llvm-toolchain-trusty-5.0
|
||||
packages:
|
||||
- clang-5.0 boost1.70 libasound2-dev libsoxr-dev libvorbisidec-dev libvorbis-dev libflac-dev libopus-dev alsa-utils libavahi-client-dev avahi-daemon
|
||||
|
||||
- os: linux
|
||||
compiler: clang
|
||||
env:
|
||||
- COMPILER=clang++-6.0
|
||||
- CXXFLAGS=-stdlib=libc++
|
||||
addons:
|
||||
apt:
|
||||
sources:
|
||||
- sourceline: 'ppa:mhier/libboost-latest'
|
||||
- llvm-toolchain-trusty-6.0
|
||||
- ubuntu-toolchain-r-test
|
||||
packages:
|
||||
- clang-6.0 boost1.70 libasound2-dev libsoxr-dev libvorbisidec-dev libvorbis-dev libflac-dev libopus-dev alsa-utils libavahi-client-dev avahi-daemon
|
||||
|
||||
- os: linux
|
||||
compiler: clang
|
||||
env:
|
||||
- COMPILER=clang++-7
|
||||
- CXXFLAGS=-stdlib=libc++
|
||||
addons:
|
||||
apt:
|
||||
sources:
|
||||
- sourceline: 'ppa:mhier/libboost-latest'
|
||||
- llvm-toolchain-trusty-7
|
||||
- ubuntu-toolchain-r-test
|
||||
packages:
|
||||
- clang-7 boost1.70 libasound2-dev libsoxr-dev libvorbisidec-dev libvorbis-dev libflac-dev libopus-dev alsa-utils libavahi-client-dev avahi-daemon
|
||||
|
||||
# build on osx
|
||||
- os: osx
|
||||
osx_image: xcode9.1
|
||||
osx_image: xcode9.4
|
||||
env:
|
||||
- MATRIX_EVAL="brew update && brew install flac libvorbis"
|
||||
allow_failures:
|
||||
- MATRIX_EVAL="brew update && brew unlink python@2 && brew upgrade boost && brew install flac opus libvorbis libsoxr"
|
||||
|
||||
- os: osx
|
||||
osx_image: xcode10.3
|
||||
env:
|
||||
- MATRIX_EVAL="brew update && brew install flac opus libvorbis libsoxr"
|
||||
|
||||
- os: osx
|
||||
osx_image: xcode11
|
||||
env:
|
||||
- MATRIX_EVAL="brew update && brew install flac opus libvorbis libsoxr"
|
||||
|
||||
# build on windows
|
||||
- os: windows
|
||||
|
||||
before_install:
|
||||
- eval "${MATRIX_EVAL}"
|
||||
- |
|
||||
(
|
||||
if [ "$TRAVIS_OS_NAME" = 'windows' ]; then
|
||||
curl -LfsS -o /tmp/travis-wait-enhanced.zip "https://github.com/crazy-max/travis-wait-enhanced/releases/download/v1.1.0/travis-wait-enhanced_1.1.0_windows_x86_64.zip"
|
||||
7z x /tmp/travis-wait-enhanced.zip -y -o/usr/bin/ travis-wait-enhanced.exe -r
|
||||
travis-wait-enhanced --version # we use this tool so travis doesn't timeout when there's no output for > 10 minutes (vcpkg has no verbose option). travis_wait also fixes this issue, but it swallows the output
|
||||
if [ ! -f "vcpkg/vcpkg.exe" ]; then # if not in cache from a previous run
|
||||
git clone https://github.com/Microsoft/vcpkg.git
|
||||
./vcpkg/bootstrap-vcpkg.bat
|
||||
travis-wait-enhanced --interval=1m --timeout=30m -- ./vcpkg/vcpkg.exe install libflac libvorbis soxr opus boost-asio --triplet x64-windows
|
||||
else
|
||||
./vcpkg/vcpkg.exe update # make sure dependencies are up to date
|
||||
fi
|
||||
fi
|
||||
)
|
||||
|
||||
script:
|
||||
- if [[ "$TRAVIS_OS_NAME" == "osx" ]]; then BUILD_PARAMS="TARGET=MACOS" ; fi
|
||||
- make $BUILD_PARAMS
|
||||
- sudo make installclient $BUILD_PARAMS
|
||||
- sudo make installserver $BUILD_PARAMS
|
||||
# make sure CXX is correctly set
|
||||
- if [[ "${COMPILER}" != "" ]] && [[ "${TRAVIS_COMPILER}" == "gcc" ]]; then export CXX=${COMPILER}; fi
|
||||
|
||||
- mkdir build
|
||||
- cd build
|
||||
- |
|
||||
(
|
||||
if [ "$TRAVIS_OS_NAME" != 'windows' ]; then
|
||||
cmake -DCMAKE_BUILD_TYPE=Release -DCMAKE_CXX_FLAGS="$CXXFLAGS -Werror -Wall -Wextra -pedantic -Wno-unused-function" .. && make && sudo make install
|
||||
else
|
||||
cmake -G "Visual Studio 15 2017 Win64" -DCMAKE_TOOLCHAIN_FILE=../vcpkg/scripts/buildsystems/vcpkg.cmake -DVCPKG_TARGET_TRIPLET=x64-windows ..
|
||||
cmake --build . --config Release
|
||||
fi
|
||||
)
|
||||
cache:
|
||||
directories:
|
||||
- vcpkg
|
237
CMakeLists.txt
Normal file
|
@ -0,0 +1,237 @@
|
|||
cmake_minimum_required(VERSION 3.2)
|
||||
|
||||
project(snapcast LANGUAGES CXX VERSION 0.20.0)
|
||||
set(PROJECT_DESCRIPTION "Multiroom client-server audio player")
|
||||
set(PROJECT_URL "https://github.com/badaix/snapcast")
|
||||
|
||||
option(BUILD_SHARED_LIBS "Build snapcast in a shared context" ON)
|
||||
option(BUILD_STATIC_LIBS "Build snapcast in a static context" ON)
|
||||
option(BUILD_TESTS "Build tests (run tests with make test)" ON)
|
||||
|
||||
if(NOT WIN32)
|
||||
option(BUILD_SERVER "Build Snapserver" ON) # no Windows server for now
|
||||
endif()
|
||||
|
||||
option(BUILD_CLIENT "Build Snapclient" ON)
|
||||
|
||||
option(BUILD_WITH_FLAC "Build with FLAC support" ON)
|
||||
option(BUILD_WITH_VORBIS "Build with VORBIS support" ON)
|
||||
option(BUILD_WITH_TREMOR "Build with vorbis using TREMOR" ON)
|
||||
option(BUILD_WITH_OPUS "Build with OPUS support" ON)
|
||||
option(BUILD_WITH_AVAHI "Build with AVAHI support" ON)
|
||||
option(BUILD_WITH_EXPAT "Build with EXPAT support" ON)
|
||||
|
||||
|
||||
if (NOT BUILD_SHARED_LIBS AND NOT BUILD_STATIC_LIBS)
|
||||
message(FATAL_ERROR "One or both of BUILD_SHARED_LIBS or BUILD_STATIC_LIBS must be set to ON to build")
|
||||
endif()
|
||||
|
||||
if (NOT BUILD_CLIENT AND NOT BUILD_SERVER)
|
||||
message(FATAL_ERROR "One or both of BUILD_CLIENT or BUILD_SERVER must be set to ON to build")
|
||||
endif()
|
||||
|
||||
if (${CMAKE_SYSTEM_NAME} MATCHES "Darwin")
|
||||
set(MACOSX TRUE)
|
||||
elseif (${CMAKE_SYSTEM_NAME} MATCHES "FreeBSD")
|
||||
set (FREEBSD TRUE)
|
||||
if (BUILD_CLIENT)
|
||||
message(FATAL_ERROR "Snapclient not yet supported for FreeBSD, use \"-DBUILD_CLIENT=OFF\"")
|
||||
endif()
|
||||
elseif (${CMAKE_SYSTEM_NAME} MATCHES "Android")
|
||||
set (ANDROID TRUE)
|
||||
add_definitions("-DASIO_DISABLE_STD_FUTURE")
|
||||
if (BUILD_SERVER)
|
||||
message(FATAL_ERROR "Snapserver not yet supported for Android, use \"-DBUILD_SERVER=OFF\"")
|
||||
endif()
|
||||
endif()
|
||||
|
||||
# Configure paths
|
||||
if(NOT DEFINED CMAKE_INSTALL_BINDIR)
|
||||
SET(CMAKE_INSTALL_BINDIR bin CACHE
|
||||
PATH "Output directory for binary files")
|
||||
endif()
|
||||
|
||||
if(NOT DEFINED CMAKE_INSTALL_LIBDIR)
|
||||
SET(CMAKE_INSTALL_LIBDIR lib CACHE PATH "Output directory for libraries")
|
||||
endif()
|
||||
|
||||
if(NOT DEFINED CMAKE_INSTALL_INCLUDEDIR)
|
||||
SET(CMAKE_INSTALL_INCLUDEDIR include CACHE
|
||||
PATH "Output directory for header files")
|
||||
endif()
|
||||
|
||||
set(INCLUDE_DIRS
|
||||
"${CMAKE_SOURCE_DIR}"
|
||||
"${CMAKE_INSTALL_INCLUDEDIR}")
|
||||
|
||||
set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_SOURCE_DIR}/cmake/")
|
||||
add_definitions(-DVERSION="${PROJECT_VERSION}")
|
||||
|
||||
set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_SOURCE_DIR}/bin)
|
||||
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR})
|
||||
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_SOURCE_DIR}/bin)
|
||||
|
||||
# Configure compiler options
|
||||
set(CMAKE_CXX_STANDARD 14)
|
||||
|
||||
# Get arch
|
||||
include(${CMAKE_SOURCE_DIR}/cmake/TargetArch.cmake)
|
||||
target_architecture(ARCH)
|
||||
|
||||
#message(STATUS "System name: ${CMAKE_SYSTEM_NAME}")
|
||||
#message(STATUS "Architecture: ${ARCH}")
|
||||
#message(STATUS "System processor: ${CMAKE_SYSTEM_PROCESSOR}")
|
||||
|
||||
include(CheckAtomic)
|
||||
|
||||
INCLUDE(TestBigEndian)
|
||||
TEST_BIG_ENDIAN(BIGENDIAN)
|
||||
IF(${BIGENDIAN})
|
||||
add_definitions("-DIS_BIG_ENDIAN")
|
||||
ENDIF(${BIGENDIAN})
|
||||
|
||||
# Check dependencies
|
||||
|
||||
if(NOT WIN32) # no PkgConfig on Windows...
|
||||
find_package(PkgConfig REQUIRED)
|
||||
endif()
|
||||
|
||||
find_package(Threads REQUIRED)
|
||||
|
||||
include(CMakePushCheckState)
|
||||
include(CheckIncludeFileCXX)
|
||||
include_directories(${INCLUDE_DIRS})
|
||||
|
||||
include(${CMAKE_SOURCE_DIR}/cmake/CheckCXX11StringSupport.cmake)
|
||||
|
||||
CHECK_CXX11_STRING_SUPPORT(HAS_CXX11_STRING_SUPPORT)
|
||||
if(NOT HAS_CXX11_STRING_SUPPORT)
|
||||
add_definitions("-DNO_CPP11_STRING")
|
||||
endif()
|
||||
|
||||
|
||||
if(NOT WIN32)
|
||||
|
||||
if(MACOSX)
|
||||
set(BONJOUR_FOUND true)
|
||||
if (BONJOUR_FOUND)
|
||||
add_definitions(-DHAS_BONJOUR)
|
||||
endif (BONJOUR_FOUND)
|
||||
|
||||
add_definitions(-DFREEBSD -DHAS_DAEMON)
|
||||
link_directories("/usr/local/lib")
|
||||
list(APPEND INCLUDE_DIRS "/usr/local/include")
|
||||
list(APPEND CMAKE_REQUIRED_INCLUDES "${INCLUDE_DIRS}")
|
||||
elseif(ANDROID)
|
||||
# add_definitions("-DNO_CPP11_STRING")
|
||||
else()
|
||||
if (BUILD_CLIENT)
|
||||
pkg_search_module(ALSA REQUIRED alsa)
|
||||
if (ALSA_FOUND)
|
||||
add_definitions(-DHAS_ALSA)
|
||||
endif (ALSA_FOUND)
|
||||
endif()
|
||||
|
||||
if(BUILD_WITH_AVAHI)
|
||||
pkg_search_module(AVAHI avahi-client)
|
||||
if (AVAHI_FOUND)
|
||||
add_definitions(-DHAS_AVAHI)
|
||||
endif (AVAHI_FOUND)
|
||||
endif(BUILD_WITH_AVAHI)
|
||||
|
||||
add_definitions(-DHAS_DAEMON)
|
||||
|
||||
if(FREEBSD)
|
||||
add_definitions(-DFREEBSD)
|
||||
link_directories("/usr/local/lib")
|
||||
list(APPEND INCLUDE_DIRS "/usr/local/include")
|
||||
list(APPEND CMAKE_REQUIRED_INCLUDES "${INCLUDE_DIRS}")
|
||||
endif()
|
||||
endif()
|
||||
|
||||
|
||||
if(BUILD_WITH_FLAC)
|
||||
pkg_search_module(FLAC flac)
|
||||
if (FLAC_FOUND)
|
||||
add_definitions("-DHAS_FLAC")
|
||||
endif (FLAC_FOUND)
|
||||
endif()
|
||||
|
||||
if(BUILD_WITH_VORBIS OR BUILD_WITH_TREMOR)
|
||||
pkg_search_module(OGG ogg)
|
||||
if (OGG_FOUND)
|
||||
add_definitions("-DHAS_OGG")
|
||||
endif (OGG_FOUND)
|
||||
endif()
|
||||
|
||||
if(BUILD_WITH_VORBIS)
|
||||
pkg_search_module(VORBIS vorbis)
|
||||
if (VORBIS_FOUND)
|
||||
add_definitions("-DHAS_VORBIS")
|
||||
endif (VORBIS_FOUND)
|
||||
endif()
|
||||
|
||||
if(BUILD_WITH_TREMOR)
|
||||
pkg_search_module(TREMOR vorbisidec)
|
||||
if (TREMOR_FOUND)
|
||||
add_definitions("-DHAS_TREMOR")
|
||||
endif (TREMOR_FOUND)
|
||||
endif()
|
||||
|
||||
if(BUILD_WITH_VORBIS)
|
||||
pkg_search_module(VORBISENC vorbisenc)
|
||||
if (VORBISENC_FOUND)
|
||||
add_definitions("-DHAS_VORBIS_ENC")
|
||||
endif(VORBISENC_FOUND)
|
||||
endif()
|
||||
|
||||
if(BUILD_WITH_OPUS)
|
||||
pkg_search_module(OPUS opus)
|
||||
if (OPUS_FOUND)
|
||||
add_definitions("-DHAS_OPUS")
|
||||
endif (OPUS_FOUND)
|
||||
endif()
|
||||
|
||||
if(BUILD_WITH_EXPAT)
|
||||
pkg_search_module(EXPAT expat)
|
||||
if (EXPAT_FOUND)
|
||||
add_definitions("-DHAS_EXPAT")
|
||||
endif (EXPAT_FOUND)
|
||||
endif()
|
||||
endif()
|
||||
|
||||
find_package(Boost 1.70 REQUIRED)
|
||||
add_definitions("-DBOOST_ERROR_CODE_HEADER_ONLY")
|
||||
|
||||
if(WIN32)
|
||||
include(FindPackageHandleStandardArgs)
|
||||
|
||||
find_path(FLAC_INCLUDE_DIRS FLAC/all.h)
|
||||
find_library(FLAC_LIBRARIES FLAC)
|
||||
find_package_handle_standard_args(FLAC DEFAULT_MSG FLAC_INCLUDE_DIRS FLAC_LIBRARIES)
|
||||
|
||||
find_path(OGG_INCLUDE_DIRS ogg/ogg.h)
|
||||
find_library(OGG_LIBRARIES ogg)
|
||||
find_package_handle_standard_args(Ogg DEFAULT_MSG OGG_INCLUDE_DIRS OGG_LIBRARIES)
|
||||
|
||||
find_path(VORBIS_INCLUDE_DIRS vorbis/vorbisenc.h)
|
||||
find_library(VORBIS_LIBRARIES vorbis)
|
||||
find_package_handle_standard_args(Vorbis DEFAULT_MSG VORBIS_INCLUDE_DIRS VORBIS_LIBRARIES)
|
||||
|
||||
find_path(OPUS_INCLUDE_DIRS opus/opus.h)
|
||||
find_library(OPUS_LIBRARIES opus)
|
||||
find_package_handle_standard_args(Opus REQUIRED OPUS_INCLUDE_DIRS OPUS_LIBRARIES)
|
||||
|
||||
add_definitions(-DNTDDI_VERSION=0x06020000 -D_WIN32_WINNT=0x0602 -DWINVER=0x0602 -DWINDOWS -DWIN32_LEAN_AND_MEAN -DUNICODE -D_UNICODE -D_CRT_SECURE_NO_WARNINGS )
|
||||
add_definitions(-DHAS_OGG -DHAS_VORBIS -DHAS_FLAC -DHAS_VORBIS_ENC -DHAS_OPUS -DHAS_WASAPI)
|
||||
endif()
|
||||
|
||||
add_subdirectory(common)
|
||||
|
||||
if (BUILD_SERVER)
|
||||
add_subdirectory(server)
|
||||
endif()
|
||||
|
||||
if (BUILD_CLIENT)
|
||||
add_subdirectory(client)
|
||||
endif()
|
5
Makefile
|
@ -2,6 +2,11 @@
|
|||
|
||||
all: client server
|
||||
|
||||
reformat:
|
||||
find client/ -iname *.h -o -iname *.hpp -o -iname *.cpp | xargs clang-format -i
|
||||
find server/ -iname *.h -o -iname *.hpp -o -iname *.cpp | xargs clang-format -i
|
||||
find common/ -iname *.h -o -iname *.hpp -o -iname *.cpp | xargs clang-format -i
|
||||
|
||||
server:
|
||||
$(MAKE) -C server
|
||||
|
||||
|
|
247
README.md
|
@ -1,116 +1,201 @@
|
|||
Snapcast
|
||||
========
|
||||
# Snapcast
|
||||
|
||||

|
||||
|
||||
**S**y**n**chronous **a**udio **p**layer
|
||||
|
||||
**S**y**n**chronous **a**udio **p**layer
|
||||
|
||||
[](https://travis-ci.org/badaix/snapcast)
|
||||
[](https://github.com/badaix/snapcast/releases)
|
||||
[](https://www.paypal.me/badaix)
|
||||
|
||||
Snapcast is a multi-room client-server audio player, where all clients are time synchronized with the server to play perfectly synced audio. It's not a standalone player, but an extension that turns your existing audio player into a Sonos-like multi-room solution.
|
||||
The server's audio input is a named pipe `/tmp/snapfifo`. All data that is fed into this file will be send to the connected clients. One of the most generic ways to use Snapcast is in conjunction with the music player daemon ([MPD](http://www.musicpd.org/)) or [Mopidy](https://www.mopidy.com/), which can be configured to use a named pipe as audio output.
|
||||
Snapcast is a multiroom client-server audio player, where all clients are time synchronized with the server to play perfectly synced audio. It's not a standalone player, but an extension that turns your existing audio player into a Sonos-like multiroom solution.
|
||||
The server's audio input is a named pipe `/tmp/snapfifo`. All data that is fed into this file will be sent to the connected clients. One of the most generic ways to use Snapcast is in conjunction with the music player daemon ([MPD](http://www.musicpd.org/)) or [Mopidy](https://www.mopidy.com/), which can be configured to use a named pipe as audio output.
|
||||
|
||||
## How does it work
|
||||
|
||||
How does is work
|
||||
----------------
|
||||
The Snapserver reads PCM chunks from the pipe `/tmp/snapfifo`. The chunk is encoded and tagged with the local time. Supported codecs are:
|
||||
* **PCM** lossless uncompressed
|
||||
* **FLAC** lossless compressed [default]
|
||||
* **Vorbis** lossy compression
|
||||
|
||||
- **PCM** lossless uncompressed
|
||||
- **FLAC** lossless compressed [default]
|
||||
- **Vorbis** lossy compression
|
||||
- **Opus** lossy low-latency compression
|
||||
|
||||
The encoded chunk is sent via a TCP connection to the Snapclients.
|
||||
Each client does continuos time synchronization with the server, so that the client is always aware of the local server time.
|
||||
Every received chunk is first decoded and added to the client's chunk-buffer. Knowing the server's time, the chunk is played out using ALSA at the appropriate time. Time deviations are corrected by
|
||||
* skipping parts or whole chunks
|
||||
* playing silence
|
||||
* playing faster/slower
|
||||
Each client does continuous time synchronization with the server, so that the client is always aware of the local server time.
|
||||
Every received chunk is first decoded and added to the client's chunk-buffer. Knowing the server's time, the chunk is played out using a system dependend low level audio API (e.g. ALSA) at the appropriate time. Time deviations are corrected by playing faster/slower, which is done by removing/duplicating single samples (a sample at 48kHz has a duration of ~0.02ms).
|
||||
|
||||
Typically the deviation is smaller than 1ms.
|
||||
Typically the deviation is below 0.2ms.
|
||||
|
||||
Installation
|
||||
------------
|
||||
You can either build and install snapcast from source, or on debian systems install a prebuild .deb package
|
||||
For more information on the binary protocol, please see the [documentation](doc/binary_protocol.md).
|
||||
|
||||
### Installation from source
|
||||
Please follow this [guide](doc/build.md) to build Snapcast for
|
||||
* [Linux](doc/build.md#linux-native)
|
||||
* [FreeBSD](doc/build.md#freebsd-native)
|
||||
* [macOS](doc/build.md#macos-native)
|
||||
* [Android](doc/build.md#android-cross-compile)
|
||||
* [OpenWrt](doc/build.md#openwrtlede-cross-compile)
|
||||
* [Buildroot](doc/build.md#buildroot-cross-compile)
|
||||
* [Raspberry Pi](doc/build.md#raspberry-pi-cross-compile)
|
||||
## Installation
|
||||
|
||||
You can either install Snapcast from a prebuilt package (recommended for new users), or build and install snapcast from source.
|
||||
|
||||
### Install Linux packages (recommended for beginners)
|
||||
|
||||
Snapcast packages are available for several Linux distributions.
|
||||
|
||||
#### Debian
|
||||
|
||||
For Debian (and Debian-based systems, such as Ubuntu, Linux Mint, ElementaryOS) download the package for your CPU architecture from the [latest release page](https://github.com/badaix/snapcast/releases/latest).
|
||||
|
||||
e.g. for Raspberry Pi `snapclient_0.x.x_armhf.deb`, for laptops `snapclient_0.x.x_amd64.deb`
|
||||
|
||||
##### using apt 1.1 or later
|
||||
|
||||
sudo apt install </path/to/snapclient_0.x.x_armhf.deb>
|
||||
|
||||
or
|
||||
|
||||
sudo apt install </path/to/snapserver_0.x.x_armhf.deb>
|
||||
|
||||
##### using dpkg
|
||||
|
||||
### Install debian packages
|
||||
Download the debian package for your CPU architecture from the [latest release page](https://github.com/badaix/snapcast/releases/latest), e.g. for Raspberry pi `snapclient_0.x.x_armhf.deb`
|
||||
Install the package:
|
||||
|
||||
$ sudo dpkg -i snapclient_0.x.x_armhf.deb
|
||||
sudo dpkg -i snapclient_0.x.x_armhf.deb
|
||||
|
||||
or
|
||||
|
||||
sudo dpkg -i snapclient_0.x.x_amd64.deb
|
||||
|
||||
Install missing dependencies:
|
||||
|
||||
$ sudo apt-get -f install
|
||||
sudo apt-get -f install
|
||||
|
||||
#### OpenWrt
|
||||
|
||||
On OpenWrt do:
|
||||
|
||||
$ opkg install snapclient_0.x.x_ar71xx.ipk
|
||||
opkg install snapclient_0.x.x_ar71xx.ipk
|
||||
|
||||
#### Alpine Linux
|
||||
|
||||
On Alpine Linux do:
|
||||
|
||||
apk add snapcast
|
||||
|
||||
Or, for just the client:
|
||||
|
||||
apk add snapcast-client
|
||||
|
||||
Or, for just the server:
|
||||
|
||||
apk add snapcast-server
|
||||
|
||||
#### Gentoo Linux
|
||||
|
||||
On Gentoo Linux do:
|
||||
|
||||
emerge --ask media-sound/snapcast
|
||||
|
||||
#### Archlinux
|
||||
|
||||
On Archlinux, Snapcast is available through the AUR. To install, use your favorite AUR helper, or do:
|
||||
|
||||
git clone https://aur.archlinux.org/snapcast
|
||||
cd snapcast
|
||||
makepkg -si
|
||||
|
||||
#### Void Linux
|
||||
|
||||
To install the client:
|
||||
|
||||
# xbps-install snapclient
|
||||
|
||||
To install the server:
|
||||
|
||||
# xbps-install snapserver
|
||||
|
||||
### Installation from source
|
||||
|
||||
Please follow this [guide](doc/build.md) to build Snapcast for
|
||||
|
||||
- [Linux](doc/build.md#linux-native)
|
||||
- [FreeBSD](doc/build.md#freebsd-native)
|
||||
- [macOS](doc/build.md#macos-native)
|
||||
- [Android](doc/build.md#android-cross-compile)
|
||||
- [OpenWrt](doc/build.md#openwrtlede-cross-compile)
|
||||
- [Buildroot](doc/build.md#buildroot-cross-compile)
|
||||
- [Raspberry Pi](doc/build.md#raspberry-pi-cross-compile)
|
||||
|
||||
## SnapOS
|
||||
|
||||
The bravest among you may be interested in [SnapOS](https://github.com/badaix/snapos), a small and fast-booting "just enough" OS to run Snapcast as an appliance.
|
||||
|
||||
There is a guide (with the necessary buildfiles) available to build SnapOS, which comes in two flavors:
|
||||
|
||||
- [Buildroot](https://github.com/badaix/snapos/blob/master/buildroot-external/README.md) based, or
|
||||
- [OpenWrt](https://github.com/badaix/snapos/tree/master/openwrt) based.
|
||||
|
||||
Please note that there are no pre-built firmware packages available.
|
||||
|
||||
## Configuration
|
||||
|
||||
Configuration
|
||||
-------------
|
||||
After installation, Snapserver and Snapclient are started with the command line arguments that are configured in `/etc/default/snapserver` and `/etc/default/snapclient`.
|
||||
Allowed options are listed in the man pages (`man snapserver`, `man snapclient`) or by invoking the snapserver or snapclient with the `-h` option.
|
||||
|
||||
Different streams can by configured with a list of `-s` options, e.g.:
|
||||
The server configuration is done in `/etc/snapserver.conf`. Different streams can by configured in the `[stream]` section with a list of `stream` options, e.g.:
|
||||
|
||||
SNAPSERVER_OPTS="-d -s pipe:///tmp/snapfifo?name=Radio&sampleformat=48000:16:2&codec=flac -s file:///home/user/Musik/Some%20wave%20file.wav?name=File"
|
||||
[stream]
|
||||
stream = pipe:///tmp/snapfifo?name=Radio&sampleformat=48000:16:2&codec=flac
|
||||
stream = file:///home/user/Musik/Some%20wave%20file.wav?name=File
|
||||
|
||||
The pipe stream (`stream = pipe`) will per default create the pipe. Sometimes your audio source might insist in creating the pipe itself. So the pipe creation mode can by changed to "not create, but only read mode", using the `mode` option set to `create` or `read`:
|
||||
|
||||
stream = pipe:///tmp/snapfifo?name=Radio&mode=read"
|
||||
|
||||
## Test
|
||||
|
||||
The pipe stream (`-s pipe`) will per default create the pipe. Sometimes your audio source might insist in creating the pipe itself. So the pipe creation mode can by changed to "not create, but only read mode", using the `mode` option set to `create` or `read`:
|
||||
|
||||
SNAPSERVER_OPTS="-d -s pipe:///tmp/snapfifo?name=Radio&mode=read"
|
||||
|
||||
Test
|
||||
----
|
||||
You can test your installation by copying random data into the server's fifo file
|
||||
|
||||
$ sudo cat /dev/urandom > /tmp/snapfifo
|
||||
sudo cat /dev/urandom > /tmp/snapfifo
|
||||
|
||||
All connected clients should play random noise now. You might raise the client's volume with "alsamixer".
|
||||
It's also possible to let the server play a wave file. Simply configure a `file` stream in `/etc/default/snapserver`, and restart the server:
|
||||
It's also possible to let the server play a WAV file. Simply configure a `file` stream in `/etc/snapserver.conf`, and restart the server:
|
||||
|
||||
SNAPSERVER_OPTS="-d -s file:///home/user/Musik/Some%20wave%20file.wav?name=test"
|
||||
[stream]
|
||||
stream = file:///home/user/Musik/Some%20wave%20file.wav?name=test
|
||||
|
||||
When you are using a Raspberry pi, you might have to change your audio output to the 3.5mm jack:
|
||||
When you are using a Raspberry Pi, you might have to change your audio output to the 3.5mm jack:
|
||||
|
||||
#The last number is the audio output with 1 being the 3.5 jack, 2 being HDMI and 0 being auto.
|
||||
$ amixer cset numid=3 1
|
||||
amixer cset numid=3 1
|
||||
|
||||
To setup WiFi on a raspberry pi, you can follow this guide:
|
||||
https://www.raspberrypi.org/documentation/configuration/wireless/wireless-cli.md
|
||||
To setup WiFi on a Raspberry Pi, you can follow this [guide](https://www.raspberrypi.org/documentation/configuration/wireless/wireless-cli.md)
|
||||
|
||||
## Control
|
||||
|
||||
Control
|
||||
-------
|
||||
Snapcast can be controlled using a [JSON-RPC API](doc/json_rpc_api/v2_0_0.md):
|
||||
* Set client's volume
|
||||
* Mute clients
|
||||
* Rename clients
|
||||
* Assign a client to a stream
|
||||
* ...
|
||||
|
||||
There is an Android client available in [Releases](https://github.com/badaix/snapcast/releases/latest)
|
||||
- Set client's volume
|
||||
- Mute clients
|
||||
- Rename clients
|
||||
- Assign a client to a stream
|
||||
- ...
|
||||
|
||||
There is an Android client [snapdroid](https://github.com/badaix/snapdroid) available in [Releases](https://github.com/badaix/snapdroid/releases/latest) and on [Google Play](https://play.google.com/store/apps/details?id=de.badaix.snapcast)
|
||||
|
||||

|
||||
|
||||
There is also an unofficial WebApp from @atoomic [atoomic/snapcast-volume-ui](https://github.com/atoomic/snapcast-volume-ui).
|
||||
This app list all clients connected to a server and allow to control individualy the volume of each client.
|
||||
This app lists all clients connected to a server and allows you to control individually the volume of each client.
|
||||
Once installed, you can use any mobile device, laptop, desktop, or browser.
|
||||
|
||||
There is also an [unofficial FHEM module](https://forum.fhem.de/index.php/topic,62389.0.html) from @unimatrix27 which integrates a snapcast controller in to the [FHEM](https://fhem.de/fhem.html) home automation system.
|
||||
There is also an [unofficial FHEM module](https://forum.fhem.de/index.php/topic,62389.0.html) from @unimatrix27 which integrates a Snapcast controller into the [FHEM](https://fhem.de/fhem.html) home automation system.
|
||||
|
||||
There is a [snapcast component for Home Assistant](https://home-assistant.io/components/media_player.snapcast/) which integrates a snapcast controller in to the [Home Assistant](https://home-assistant.io/) home automation system.
|
||||
There is a [snapcast component for Home Assistant](https://home-assistant.io/components/media_player.snapcast/) which integrates a Snapcast controller in to the [Home Assistant](https://home-assistant.io/) home automation system.
|
||||
|
||||
For a web interface in Python, see [snapcastr](https://github.com/xkonni/snapcastr), based on [python-snapcast](https://github.com/happyleavesaoc/python-snapcast). This interface controls client volume and assigns streams to groups.
|
||||
|
||||
Another web interface running on any device is [snapcast-websockets-ui](https://github.com/derglaus/snapcast-websockets-ui), running entirely in the browser, which needs [websockify](https://github.com/novnc/websockify). No configuration needed; features almost all functions; still needs some tuning for the optics.
|
||||
|
||||
A web interface called [HydraPlay](https://github.com/mariolukas/HydraPlay) integrates Snapcast and multiple Mopidy instances. It is JavaScript based and uses Angular 7. A Snapcast web socket proxy server is needed to connect Snapcast to HydraPlay over web sockets.
|
||||
|
||||
## Setup of audio players/server
|
||||
|
||||
Setup of audio players/server
|
||||
-----------------------------
|
||||
Snapcast can be used with a number of different audio players and servers, and so it can be integrated into your favorite audio-player solution and make it synced-multiroom capable.
|
||||
The only requirement is that the player's audio can be redirected into the Snapserver's fifo `/tmp/snapfifo`. In the following configuration hints for [MPD](http://www.musicpd.org/) and [Mopidy](https://www.mopidy.com/) are given, which are base of other audio player solutions, like [Volumio](https://volumio.org/) or [RuneAudio](http://www.runeaudio.com/) (both MPD) or [Pi MusicBox](http://www.pimusicbox.com/) (Mopidy).
|
||||
|
||||
|
@ -119,29 +204,31 @@ The goal is to build the following chain:
|
|||
audio player software -> snapfifo -> snapserver -> network -> snapclient -> alsa
|
||||
|
||||
This [guide](doc/player_setup.md) shows how to configure different players/audio sources to redirect their audio signal into the Snapserver's fifo:
|
||||
* [MPD](doc/player_setup.md#mpd)
|
||||
* [Mopidy](doc/player_setup.md#mopidy)
|
||||
* [FFmpeg](doc/player_setup.md#ffmpeg)
|
||||
* [mpv](doc/player_setup.md#mpv)
|
||||
* [MPlayer](doc/player_setup.md#mplayer)
|
||||
* [Alsa](doc/player_setup.md#alsa)
|
||||
* [PulseAudio](doc/player_setup.md#pulseaudio)
|
||||
* [AirPlay](doc/player_setup.md#airplay)
|
||||
* [Spotify](doc/player_setup.md#spotify)
|
||||
* [Process](doc/player_setup.md#process)
|
||||
* [Line-in](doc/player_setup.md#line-in)
|
||||
|
||||
Roadmap
|
||||
-------
|
||||
- [MPD](doc/player_setup.md#mpd)
|
||||
- [Mopidy](doc/player_setup.md#mopidy)
|
||||
- [FFmpeg](doc/player_setup.md#ffmpeg)
|
||||
- [mpv](doc/player_setup.md#mpv)
|
||||
- [MPlayer](doc/player_setup.md#mplayer)
|
||||
- [Alsa](doc/player_setup.md#alsa)
|
||||
- [PulseAudio](doc/player_setup.md#pulseaudio)
|
||||
- [AirPlay](doc/player_setup.md#airplay)
|
||||
- [Spotify](doc/player_setup.md#spotify)
|
||||
- [Process](doc/player_setup.md#process)
|
||||
- [Line-in](doc/player_setup.md#line-in)
|
||||
|
||||
## Roadmap
|
||||
|
||||
Unordered list of features that should make it into the v1.0
|
||||
- [X] **Remote control** JSON-RPC API to change client latency, volume, zone, ...
|
||||
|
||||
- [X] **Remote control** JSON-RPC API to change client latency, volume, zone,...
|
||||
- [X] **Android client** JSON-RPC client and Snapclient
|
||||
- [X] **Streams** Support multiple streams
|
||||
- [X] **Debian packages** prebuild deb packages
|
||||
- [X] **Endian** independent code
|
||||
- [X] **OpenWrt** port Snapclient to OpenWrt
|
||||
- [X] **Hi-Res audio** support (like 192kHz 24bit)
|
||||
- [X] **Hi-Res audio** support (like 96kHz 24bit)
|
||||
- [X] **Groups** support multiple Groups of clients ("Zones")
|
||||
- [ ] **JSON-RPC** Possibility to add, remove, rename streams
|
||||
- [ ] **Protocol specification** Snapcast binary streaming protocol, JSON-RPC protocol
|
||||
- [ ] **Ports** Snapclient for Windows, ~~Mac OS X~~, ...
|
||||
- [ ] **Ports** Snapclient for Windows, ~~Mac OS X~~,...
|
||||
|
|
28
TODO.md
Normal file
|
@ -0,0 +1,28 @@
|
|||
TODO
|
||||
====
|
||||
|
||||
General
|
||||
-------
|
||||
|
||||
- Update Readme.md
|
||||
- JsonRPC documentation
|
||||
- Server ping client?
|
||||
- UDP based audio streaming
|
||||
|
||||
Server
|
||||
------
|
||||
|
||||
- [fd stream](https://gstreamer.freedesktop.org/data/doc/gstreamer/head/gstreamer-plugins/html/gstreamer-plugins-fdsink.html)
|
||||
- gstreamer snapcast sink plugin?
|
||||
- "sync" option for streams (realtime reading vs read as much as available)
|
||||
- #402: Add meta stream that reads the input of other streams (in some fallback hierarchy manner: when the first one plays, use this signal, else if the second is playing, take this, ...).
|
||||
|
||||
Client
|
||||
------
|
||||
|
||||
- Add option to not play in sync, i.e. not change the tempo
|
||||
|
||||
Issues
|
||||
------
|
||||
|
||||
- Android clean data structures after changing the Server
|
8
android/.gitignore
vendored
|
@ -1,8 +0,0 @@
|
|||
*.iml
|
||||
.gradle
|
||||
/local.properties
|
||||
/.idea/workspace.xml
|
||||
/.idea/libraries
|
||||
.DS_Store
|
||||
/build
|
||||
/captures
|
1
android/.idea/.name
generated
|
@ -1 +0,0 @@
|
|||
android
|
22
android/.idea/compiler.xml
generated
|
@ -1,22 +0,0 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="CompilerConfiguration">
|
||||
<resourceExtensions />
|
||||
<wildcardResourcePatterns>
|
||||
<entry name="!?*.java" />
|
||||
<entry name="!?*.form" />
|
||||
<entry name="!?*.class" />
|
||||
<entry name="!?*.groovy" />
|
||||
<entry name="!?*.scala" />
|
||||
<entry name="!?*.flex" />
|
||||
<entry name="!?*.kt" />
|
||||
<entry name="!?*.clj" />
|
||||
<entry name="!?*.aj" />
|
||||
</wildcardResourcePatterns>
|
||||
<annotationProcessing>
|
||||
<profile default="true" name="Default" enabled="false">
|
||||
<processorPath useClasspath="true" />
|
||||
</profile>
|
||||
</annotationProcessing>
|
||||
</component>
|
||||
</project>
|
6
android/.idea/copyright/Snapcast.xml
generated
|
@ -1,6 +0,0 @@
|
|||
<component name="CopyrightManager">
|
||||
<copyright>
|
||||
<option name="myName" value="Snapcast" />
|
||||
<option name="notice" value=" This file is part of snapcast Copyright (C) 2014-2017 Johannes Pohl This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program. If not, see <http://www.gnu.org/licenses/>." />
|
||||
</copyright>
|
||||
</component>
|
7
android/.idea/copyright/profiles_settings.xml
generated
|
@ -1,7 +0,0 @@
|
|||
<component name="CopyrightManager">
|
||||
<settings default="Snapcast">
|
||||
<module2copyright>
|
||||
<element module="All" copyright="Snapcast" />
|
||||
</module2copyright>
|
||||
</settings>
|
||||
</component>
|
6
android/.idea/encodings.xml
generated
|
@ -1,6 +0,0 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="Encoding">
|
||||
<file url="PROJECT" charset="UTF-8" />
|
||||
</component>
|
||||
</project>
|
19
android/.idea/gradle.xml
generated
|
@ -1,19 +0,0 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="GradleSettings">
|
||||
<option name="linkedExternalProjectsSettings">
|
||||
<GradleProjectSettings>
|
||||
<option name="distributionType" value="LOCAL" />
|
||||
<option name="externalProjectPath" value="$PROJECT_DIR$" />
|
||||
<option name="gradleHome" value="$APPLICATION_HOME_DIR$/gradle/gradle-2.14.1" />
|
||||
<option name="modules">
|
||||
<set>
|
||||
<option value="$PROJECT_DIR$" />
|
||||
<option value="$PROJECT_DIR$/Snapcast" />
|
||||
</set>
|
||||
</option>
|
||||
<option name="resolveModulePerSourceSet" value="false" />
|
||||
</GradleProjectSettings>
|
||||
</option>
|
||||
</component>
|
||||
</project>
|
46
android/.idea/misc.xml
generated
|
@ -1,46 +0,0 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="EntryPointsManager">
|
||||
<entry_points version="2.0" />
|
||||
</component>
|
||||
<component name="NullableNotNullManager">
|
||||
<option name="myDefaultNullable" value="android.support.annotation.Nullable" />
|
||||
<option name="myDefaultNotNull" value="android.support.annotation.NonNull" />
|
||||
<option name="myNullables">
|
||||
<value>
|
||||
<list size="4">
|
||||
<item index="0" class="java.lang.String" itemvalue="org.jetbrains.annotations.Nullable" />
|
||||
<item index="1" class="java.lang.String" itemvalue="javax.annotation.Nullable" />
|
||||
<item index="2" class="java.lang.String" itemvalue="edu.umd.cs.findbugs.annotations.Nullable" />
|
||||
<item index="3" class="java.lang.String" itemvalue="android.support.annotation.Nullable" />
|
||||
</list>
|
||||
</value>
|
||||
</option>
|
||||
<option name="myNotNulls">
|
||||
<value>
|
||||
<list size="4">
|
||||
<item index="0" class="java.lang.String" itemvalue="org.jetbrains.annotations.NotNull" />
|
||||
<item index="1" class="java.lang.String" itemvalue="javax.annotation.Nonnull" />
|
||||
<item index="2" class="java.lang.String" itemvalue="edu.umd.cs.findbugs.annotations.NonNull" />
|
||||
<item index="3" class="java.lang.String" itemvalue="android.support.annotation.NonNull" />
|
||||
</list>
|
||||
</value>
|
||||
</option>
|
||||
</component>
|
||||
<component name="ProjectLevelVcsManager" settingsEditedManually="false">
|
||||
<OptionsSetting value="true" id="Add" />
|
||||
<OptionsSetting value="true" id="Remove" />
|
||||
<OptionsSetting value="true" id="Checkout" />
|
||||
<OptionsSetting value="true" id="Update" />
|
||||
<OptionsSetting value="true" id="Status" />
|
||||
<OptionsSetting value="true" id="Edit" />
|
||||
<ConfirmationsSetting value="0" id="Add" />
|
||||
<ConfirmationsSetting value="0" id="Remove" />
|
||||
</component>
|
||||
<component name="ProjectRootManager" version="2" languageLevel="JDK_1_7" default="true" assert-keyword="true" jdk-15="true" project-jdk-name="1.8" project-jdk-type="JavaSDK">
|
||||
<output url="file://$PROJECT_DIR$/build/classes" />
|
||||
</component>
|
||||
<component name="ProjectType">
|
||||
<option name="id" value="Android" />
|
||||
</component>
|
||||
</project>
|
9
android/.idea/modules.xml
generated
|
@ -1,9 +0,0 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="ProjectModuleManager">
|
||||
<modules>
|
||||
<module fileurl="file://$PROJECT_DIR$/Snapcast/Snapcast.iml" filepath="$PROJECT_DIR$/Snapcast/Snapcast.iml" />
|
||||
<module fileurl="file://$PROJECT_DIR$/android.iml" filepath="$PROJECT_DIR$/android.iml" />
|
||||
</modules>
|
||||
</component>
|
||||
</project>
|
12
android/.idea/runConfigurations.xml
generated
|
@ -1,12 +0,0 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="RunConfigurationProducerService">
|
||||
<option name="ignoredProducers">
|
||||
<set>
|
||||
<option value="org.jetbrains.plugins.gradle.execution.test.runner.AllInPackageGradleConfigurationProducer" />
|
||||
<option value="org.jetbrains.plugins.gradle.execution.test.runner.TestClassGradleConfigurationProducer" />
|
||||
<option value="org.jetbrains.plugins.gradle.execution.test.runner.TestMethodGradleConfigurationProducer" />
|
||||
</set>
|
||||
</option>
|
||||
</component>
|
||||
</project>
|
6
android/.idea/vcs.xml
generated
|
@ -1,6 +0,0 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="VcsDirectoryMappings">
|
||||
<mapping directory="$PROJECT_DIR$/.." vcs="Git" />
|
||||
</component>
|
||||
</project>
|
1
android/Snapcast/.gitignore
vendored
|
@ -1 +0,0 @@
|
|||
/build
|
|
@ -1,74 +0,0 @@
|
|||
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
|
||||
<svg
|
||||
xmlns:dc="http://purl.org/dc/elements/1.1/"
|
||||
xmlns:cc="http://creativecommons.org/ns#"
|
||||
xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
|
||||
xmlns:svg="http://www.w3.org/2000/svg"
|
||||
xmlns="http://www.w3.org/2000/svg"
|
||||
xmlns:sodipodi="http://sodipodi.sourceforge.net/DTD/sodipodi-0.dtd"
|
||||
xmlns:inkscape="http://www.inkscape.org/namespaces/inkscape"
|
||||
xml:space="preserve"
|
||||
version="1.0"
|
||||
id="layer1"
|
||||
width="400pt"
|
||||
height="400pt"
|
||||
viewBox="0 0 75 75"
|
||||
inkscape:version="0.48.3.1 r9886"
|
||||
sodipodi:docname="Mute_Icon.svg"><defs
|
||||
id="defs3007" /><sodipodi:namedview
|
||||
pagecolor="#ffffff"
|
||||
bordercolor="#666666"
|
||||
borderopacity="1"
|
||||
objecttolerance="10"
|
||||
gridtolerance="10"
|
||||
guidetolerance="10"
|
||||
inkscape:pageopacity="0"
|
||||
inkscape:pageshadow="2"
|
||||
inkscape:window-width="1920"
|
||||
inkscape:window-height="1028"
|
||||
id="namedview3005"
|
||||
showgrid="false"
|
||||
showguides="true"
|
||||
inkscape:guide-bbox="true"
|
||||
inkscape:zoom="0.649"
|
||||
inkscape:cx="-282.4196"
|
||||
inkscape:cy="171.8348"
|
||||
inkscape:window-x="-8"
|
||||
inkscape:window-y="-8"
|
||||
inkscape:window-maximized="1"
|
||||
inkscape:current-layer="g1"
|
||||
inkscape:snap-smooth-nodes="false"
|
||||
inkscape:object-paths="false"><sodipodi:guide
|
||||
orientation="0,1"
|
||||
position="42.491779,326.85984"
|
||||
id="guide3009" /><sodipodi:guide
|
||||
orientation="0,1"
|
||||
position="118.64407,164.86903"
|
||||
id="guide3011" /><sodipodi:guide
|
||||
orientation="1,0"
|
||||
position="324.34515,194.53005"
|
||||
id="guide3005" /><sodipodi:guide
|
||||
orientation="1,0"
|
||||
position="462.63482,170.64715"
|
||||
id="guide3007" /></sodipodi:namedview><metadata
|
||||
id="metadata1"><rdf:RDF><cc:Work
|
||||
rdf:about=""><dc:format>image/svg+xml</dc:format><dc:type
|
||||
rdf:resource="http://purl.org/dc/dcmitype/StillImage" /><dc:title /></cc:Work></rdf:RDF></metadata><g
|
||||
id="g1"><polygon
|
||||
id="polygon1"
|
||||
points="39.389,13.769 22.235,28.606 6,28.606 6,47.699 21.989,47.699 39.389,62.75 39.389,13.769"
|
||||
style="stroke:#111111;stroke-width:5;stroke-linejoin:round;fill:#111111;" />
|
||||
|
||||
<path
|
||||
id="path3003"
|
||||
d="M 48.651772,50.269646 69.395223,25.971024"
|
||||
style="fill:none;stroke:#111111;stroke-width:5;stroke-linecap:round"
|
||||
inkscape:connector-curvature="0"
|
||||
sodipodi:nodetypes="cc" />
|
||||
<path
|
||||
id="path3003-1"
|
||||
d="M 69.395223,50.269646 48.651772,25.971024"
|
||||
style="fill:none;stroke:#111111;stroke-width:5;stroke-linecap:round"
|
||||
inkscape:connector-curvature="0"
|
||||
sodipodi:nodetypes="cc" /></g>
|
||||
</svg>
|
Before Width: | Height: | Size: 2.5 KiB |
|
@ -1,30 +0,0 @@
|
|||
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
|
||||
<svg
|
||||
xmlns:dc="http://purl.org/dc/elements/1.1/"
|
||||
xmlns:cc="http://web.resource.org/cc/"
|
||||
xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
|
||||
xmlns:svg="http://www.w3.org/2000/svg"
|
||||
xmlns="http://www.w3.org/2000/svg"
|
||||
xml:space="preserve"
|
||||
version="1.0"
|
||||
id="layer1"
|
||||
width="400pt" height="400pt"
|
||||
viewBox="0 0 75 75"><metadata
|
||||
id="metadata1"><rdf:RDF><cc:Work
|
||||
rdf:about=""><dc:format>image/svg+xml</dc:format><dc:type
|
||||
rdf:resource="http://purl.org/dc/dcmitype/StillImage" /></cc:Work></rdf:RDF></metadata><g
|
||||
id="g1"><polygon
|
||||
id="polygon1"
|
||||
points="39.389,13.769 22.235,28.606 6,28.606 6,47.699 21.989,47.699 39.389,62.75 39.389,13.769"
|
||||
style="stroke:#111111;stroke-width:5;stroke-linejoin:round;fill:#111111;"
|
||||
/><path id="path1"
|
||||
d="M 48.128,49.03 C 50.057,45.934 51.19,42.291 51.19,38.377 C 51.19,34.399 50.026,30.703 48.043,27.577"
|
||||
style="fill:none;stroke:#111111;stroke-width:5;stroke-linecap:round"/>
|
||||
<path id="path2"
|
||||
d="M 55.082,20.537 C 58.777,25.523 60.966,31.694 60.966,38.377 C 60.966,44.998 58.815,51.115 55.178,56.076"
|
||||
style="fill:none;stroke:#111111;stroke-width:5;stroke-linecap:round"/>
|
||||
<path id="path1"
|
||||
d="M 61.71,62.611 C 66.977,55.945 70.128,47.531 70.128,38.378 C 70.128,29.161 66.936,20.696 61.609,14.01"
|
||||
style="fill:none;stroke:#111111;stroke-width:5;stroke-linecap:round"/>
|
||||
</g>
|
||||
</svg>
|
Before Width: | Height: | Size: 1.3 KiB |
|
@ -1,34 +0,0 @@
|
|||
apply plugin: 'com.android.application'
|
||||
|
||||
android {
|
||||
compileSdkVersion 25
|
||||
buildToolsVersion '25.0.2'
|
||||
|
||||
defaultConfig {
|
||||
applicationId "de.badaix.snapcast"
|
||||
minSdkVersion 16
|
||||
targetSdkVersion 25
|
||||
versionCode 1200
|
||||
versionName "0.12.0"
|
||||
multiDexEnabled true
|
||||
}
|
||||
buildTypes {
|
||||
release {
|
||||
minifyEnabled false
|
||||
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
|
||||
}
|
||||
}
|
||||
lintOptions{
|
||||
disable 'MissingTranslation'
|
||||
}
|
||||
}
|
||||
|
||||
dependencies {
|
||||
compile fileTree(include: ['*.jar'], dir: 'libs')
|
||||
testCompile 'junit:junit:4.12'
|
||||
compile 'com.android.support:appcompat-v7:25.3.1'
|
||||
compile 'com.android.support:cardview-v7:25.3.1'
|
||||
compile 'com.android.support:support-v4:25.3.1'
|
||||
// compile 'com.android.support:recyclerview-v7:23.1.1'
|
||||
compile 'com.android.support:design:25.3.1'
|
||||
}
|
17
android/Snapcast/proguard-rules.pro
vendored
|
@ -1,17 +0,0 @@
|
|||
# Add project specific ProGuard rules here.
|
||||
# By default, the flags in this file are appended to flags specified
|
||||
# in /home/johannes/Develop/android-sdks/tools/proguard/proguard-android.txt
|
||||
# You can edit the include path and order by changing the proguardFiles
|
||||
# directive in build.gradle.
|
||||
#
|
||||
# For more details, see
|
||||
# http://developer.android.com/guide/developing/tools/proguard.html
|
||||
|
||||
# Add any project specific keep options here:
|
||||
|
||||
# If your project uses WebView with JS, uncomment the following
|
||||
# and specify the fully qualified class name to the JavaScript interface
|
||||
# class:
|
||||
#-keepclassmembers class fqcn.of.javascript.interface.for.webview {
|
||||
# public *;
|
||||
#}
|
|
@ -1,13 +0,0 @@
|
|||
package de.badaix.snapcast;
|
||||
|
||||
import android.app.Application;
|
||||
import android.test.ApplicationTestCase;
|
||||
|
||||
/**
|
||||
* <a href="http://d.android.com/tools/testing/testing_android.html">Testing Fundamentals</a>
|
||||
*/
|
||||
public class ApplicationTest extends ApplicationTestCase<Application> {
|
||||
public ApplicationTest() {
|
||||
super(Application.class);
|
||||
}
|
||||
}
|
|
@ -1,63 +0,0 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
package="de.badaix.snapcast">
|
||||
|
||||
<uses-permission android:name="android.permission.WAKE_LOCK"/>
|
||||
<uses-permission android:name="android.permission.INTERNET"/>
|
||||
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED"/>
|
||||
|
||||
<application
|
||||
android:allowBackup="true"
|
||||
android:icon="@mipmap/ic_launcher"
|
||||
android:label="@string/app_name"
|
||||
android:supportsRtl="true"
|
||||
android:theme="@style/AppTheme">
|
||||
<activity
|
||||
android:name=".MainActivity"
|
||||
android:configChanges="orientation|screenSize"
|
||||
android:label="@string/app_name"
|
||||
android:theme="@style/AppTheme.NoActionBar">
|
||||
<!-- android:launchMode="singleInstance" -->
|
||||
<intent-filter>
|
||||
<action android:name="android.intent.action.MAIN"/>
|
||||
|
||||
<category android:name="android.intent.category.LAUNCHER"/>
|
||||
</intent-filter>
|
||||
</activity>
|
||||
|
||||
<receiver android:name="de.badaix.snapcast.BootCompleteReceiver">
|
||||
<intent-filter>
|
||||
<action android:name="android.intent.action.BOOT_COMPLETED"/>
|
||||
</intent-filter>
|
||||
</receiver>
|
||||
|
||||
<service android:name=".SnapclientService"/>
|
||||
|
||||
<!-- android:theme="@style/Theme.AppCompat.Light.DialogWhenLarge" -->
|
||||
<activity
|
||||
android:name=".ClientSettingsActivity"
|
||||
android:label="@string/title_activity_client_settings"
|
||||
android:parentActivityName=".MainActivity">
|
||||
<meta-data
|
||||
android:name="android.support.PARENT_ACTIVITY"
|
||||
android:value=".MainActivity"/>
|
||||
</activity>
|
||||
<activity
|
||||
android:name=".GroupSettingsActivity"
|
||||
android:label="@string/title_activity_group_preference"
|
||||
android:parentActivityName=".MainActivity">
|
||||
<meta-data
|
||||
android:name="android.support.PARENT_ACTIVITY"
|
||||
android:value=".MainActivity"/>
|
||||
</activity>
|
||||
<activity
|
||||
android:name=".AboutActivity"
|
||||
android:label="@string/title_activity_about"
|
||||
android:parentActivityName=".MainActivity">
|
||||
<meta-data
|
||||
android:name="android.support.PARENT_ACTIVITY"
|
||||
android:value=".MainActivity"/>
|
||||
</activity>
|
||||
</application>
|
||||
|
||||
</manifest>
|
Before Width: | Height: | Size: 21 KiB |
|
@ -1,574 +0,0 @@
|
|||
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
|
||||
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
|
||||
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
|
||||
|
||||
<head>
|
||||
<title>Snapcast licenses</title>
|
||||
<meta http-equiv="content-type" content="text/html;charset=utf-8" />
|
||||
</head>
|
||||
|
||||
<body id="top" style="background-color: #EBEBEE">
|
||||
|
||||
<a href="https://github.com/badaix/snapcast"><img style="position: absolute; top: 0; right: 0; border: 0;" src="https://camo.githubusercontent.com/38ef81f8aca64bb9a64448d0d70f1308ef5341ab/68747470733a2f2f73332e616d617a6f6e6177732e636f6d2f6769746875622f726962626f6e732f666f726b6d655f72696768745f6461726b626c75655f3132313632312e706e67"
|
||||
alt="Fork me on GitHub" data-canonical-src="https://s3.amazonaws.com/github/ribbons/forkme_right_darkblue_121621.png"></a>
|
||||
|
||||
<img src="Snapcast_800.png" alt="Snapcast" style="max-width:90%; margin: 20px 0px 10px 5px">
|
||||
<p>Copyright © 2014 - 2017 <a href="mailto:snapcast@badaix.de">BadAix</a></p>
|
||||
<p>Author: <a href="https://de.linkedin.com/pub/johannes-pohl/65/6a6/253">Johannes Pohl</a> and <a href="https://github.com/badaix/snapcast/graphs/contributors">contributors</a></p>
|
||||
|
||||
<div>
|
||||
<h2>License</h2>
|
||||
|
||||
<p>Snapcast is licensed under the <a href="#gpl">GNU General Public License, version 3 or
|
||||
later</a> (herein referred to as GPL).</p>
|
||||
|
||||
<h2>How Can I Help?</h2>
|
||||
|
||||
<p>If you find Snapcast useful, then I'd really appreciate it if you'd consider contributing to the project however you can.
|
||||
Donating is the easiest.</p>
|
||||
|
||||
<p>You can donate Bitcoins here: <a href="bitcoin:1Cm9WL99fyYSPbLvgnGbRihjb1GYZ5aZFz?label=Snapcast%20Donation">1Cm9WL99fyYSPbLvgnGbRihjb1GYZ5aZFz</a>
|
||||
</p>
|
||||
|
||||
|
||||
<h2>Sources</h2>
|
||||
|
||||
<p>The sources to this application can be retrieved at <a href="https://github.com/badaix/snapcast">https://github.com/badaix/snapcast</a>.</p>
|
||||
|
||||
<h2>Libraries</h2>
|
||||
|
||||
<p>Snapcast uses external libraries that make extensive use of the following persons' or companies' code:
|
||||
<ul>
|
||||
<li><a href="https://source.android.com">Android Open Source Project</a> - Copyright © 2008 The Android Open Source
|
||||
Project - <a href="http://opensource.org/licenses/ISC">2-clause BSD license</a></li>
|
||||
<li><a href="https://xiph.org/flac">FLAC</a> - Copyright © 2001-2012 Josh Coalson et al. - <a href="http://www.gnu.org/licenses/gpl-2.0.txt">GPL v2 or later</a>,
|
||||
codec libs <a href="#xiph">Xiph.org BSD license</a></li>
|
||||
<li><a href="https://www.xiph.org/ogg">libogg</a> - Copyright © 2002 Xiph.org Foundation - <a href="#xiph">Xiph.org BSD
|
||||
license</a></li>
|
||||
<li><a href="http://www.avahi.org/">Avahi</a> - Copyright © 2005-2014 The Avahi Team - <a href="http://www.gnu.org/copyleft/lesser.html">LGPL</a></li>
|
||||
<li><a href="https://github.com/badaix/popl">popl</a> - Copyright © 2015-2016 Johannes Pohl - <a href="http://www.opensource.org/licenses/mit-license.php">MIT license</a></li>
|
||||
<li><a href="https://github.com/nlohmann/json">JSON for Modern C++</a> - Copyright © 2013-2016 Niels Lohmann - <a href="http://www.opensource.org/licenses/mit-license.php">MIT license</a></li>
|
||||
</ul>
|
||||
</p>
|
||||
</div>
|
||||
<p><a href="#top">Back to the top</a></p>
|
||||
|
||||
<p>
|
||||
|
||||
<div style="text-align: center">
|
||||
<a href="http://www.tnt-audio.com/topics/realstereo_e.html">
|
||||
<img src="http://www.tnt-audio.com/gif/real_stereo_small.gif" alt="We support real stereo" align="center"></a>
|
||||
</div>
|
||||
</p>
|
||||
<hr/>
|
||||
<div>
|
||||
<h3 id="gpl">GNU GENERAL PUBLIC LICENSE</h3>
|
||||
|
||||
<p>Version 3, 29 June 2007</p>
|
||||
|
||||
<p>Copyright © 2007 Free Software Foundation, Inc. <
|
||||
<a href="http://fsf.org/">http://fsf.org/</a>></p>
|
||||
|
||||
<p>
|
||||
Everyone is permitted to copy and distribute verbatim copies of this license document, but changing it is not allowed.</p>
|
||||
|
||||
<h3>
|
||||
<a name="preamble"></a>Preamble</h3>
|
||||
|
||||
<p>The GNU General Public License is a free, copyleft license for software and other kinds of works.</p>
|
||||
|
||||
<p>The licenses for most software and other practical works are designed to take away your freedom to share and change the
|
||||
works. By contrast, the GNU General Public License is intended to guarantee your freedom to share and change all versions
|
||||
of a program--to make sure it remains free software for all its users. We, the Free Software Foundation, use the GNU General
|
||||
Public License for most of our software; it applies also to any other work released this way by its authors. You can apply
|
||||
it to your programs, too.</p>
|
||||
|
||||
<p>When we speak of free software, we are referring to freedom, not price. Our General Public Licenses are designed to make
|
||||
sure that you have the freedom to distribute copies of free software (and charge for them if you wish), that you receive
|
||||
source code or can get it if you want it, that you can change the software or use pieces of it in new free programs, and
|
||||
that you know you can do these things.</p>
|
||||
|
||||
<p>To protect your rights, we need to prevent others from denying you these rights or asking you to surrender the rights.
|
||||
Therefore, you have certain responsibilities if you distribute copies of the software, or if you modify it: responsibilities
|
||||
to respect the freedom of others.</p>
|
||||
|
||||
<p>For example, if you distribute copies of such a program, whether gratis or for a fee, you must pass on to the recipients
|
||||
the same freedoms that you received. You must make sure that they, too, receive or can get the source code. And you must
|
||||
show them these terms so they know their rights.</p>
|
||||
|
||||
<p>Developers that use the GNU GPL protect your rights with two steps: (1) assert copyright on the software, and (2) offer
|
||||
you this License giving you legal permission to copy, distribute and/or modify it.</p>
|
||||
|
||||
<p>For the developers' and authors' protection, the GPL clearly explains that there is no warranty for this free software.
|
||||
For both users' and authors' sake, the GPL requires that modified versions be marked as changed, so that their problems
|
||||
will not be attributed erroneously to authors of previous versions.</p>
|
||||
|
||||
<p>Some devices are designed to deny users access to install or run modified versions of the software inside them, although
|
||||
the manufacturer can do so. This is fundamentally incompatible with the aim of protecting users' freedom to change the
|
||||
software. The systematic pattern of such abuse occurs in the area of products for individuals to use, which is precisely
|
||||
where it is most unacceptable. Therefore, we have designed this version of the GPL to prohibit the practice for those
|
||||
products. If such problems arise substantially in other domains, we stand ready to extend this provision to those domains
|
||||
in future versions of the GPL, as needed to protect the freedom of users.</p>
|
||||
|
||||
<p>Finally, every program is threatened constantly by software patents. States should not allow patents to restrict development
|
||||
and use of software on general-purpose computers, but in those that do, we wish to avoid the special danger that patents
|
||||
applied to a free program could make it effectively proprietary. To prevent this, the GPL assures that patents cannot
|
||||
be used to render the program non-free.</p>
|
||||
|
||||
<p>The precise terms and conditions for copying, distribution and modification follow.</p>
|
||||
|
||||
<h3>
|
||||
<a name="terms"></a>TERMS AND CONDITIONS</h3>
|
||||
|
||||
<h4>
|
||||
<a name="section0"></a>0. Definitions.</h4>
|
||||
|
||||
<p>“This License” refers to version 3 of the GNU General Public License.</p>
|
||||
|
||||
<p>“Copyright” also means copyright-like laws that apply to other kinds of works, such as semiconductor masks.</p>
|
||||
|
||||
<p>“The Program” refers to any copyrightable work licensed under this License. Each licensee is addressed as “you”.
|
||||
“Licensees” and “recipients” may be individuals or organizations.</p>
|
||||
|
||||
<p>To “modify” a work means to copy from or adapt all or part of the work in a fashion requiring copyright permission,
|
||||
other than the making of an exact copy. The resulting work is called a “modified version” of the earlier work
|
||||
or a work “based on” the earlier work.</p>
|
||||
|
||||
<p>A “covered work” means either the unmodified Program or a work based on the Program.</p>
|
||||
|
||||
<p>To “propagate” a work means to do anything with it that, without permission, would make you directly or secondarily
|
||||
liable for infringement under applicable copyright law, except executing it on a computer or modifying a private copy.
|
||||
Propagation includes copying, distribution (with or without modification), making available to the public, and in some
|
||||
countries other activities as well.</p>
|
||||
|
||||
<p>To “convey” a work means any kind of propagation that enables other parties to make or receive copies. Mere
|
||||
interaction with a user through a computer network, with no transfer of a copy, is not conveying.</p>
|
||||
|
||||
<p>An interactive user interface displays “Appropriate Legal Notices” to the extent that it includes a convenient
|
||||
and prominently visible feature that (1) displays an appropriate copyright notice, and (2) tells the user that there is
|
||||
no warranty for the work (except to the extent that warranties are provided), that licensees may convey the work under
|
||||
this License, and how to view a copy of this License. If the interface presents a list of user commands or options, such
|
||||
as a menu, a prominent item in the list meets this criterion.</p>
|
||||
|
||||
<h4>
|
||||
<a name="section1"></a>1. Source Code.</h4>
|
||||
|
||||
<p>The “source code” for a work means the preferred form of the work for making modifications to it. “Object
|
||||
code” means any non-source form of a work.</p>
|
||||
|
||||
<p>A “Standard Interface” means an interface that either is an official standard defined by a recognized standards
|
||||
body, or, in the case of interfaces specified for a particular programming language, one that is widely used among developers
|
||||
working in that language.</p>
|
||||
|
||||
<p>The “System Libraries” of an executable work include anything, other than the work as a whole, that (a) is
|
||||
included in the normal form of packaging a Major Component, but which is not part of that Major Component, and (b) serves
|
||||
only to enable use of the work with that Major Component, or to implement a Standard Interface for which an implementation
|
||||
is available to the public in source code form. A “Major Component”, in this context, means a major essential
|
||||
component (kernel, window system, and so on) of the specific operating system (if any) on which the executable work runs,
|
||||
or a compiler used to produce the work, or an object code interpreter used to run it.</p>
|
||||
|
||||
<p>The “Corresponding Source” for a work in object code form means all the source code needed to generate, install,
|
||||
and (for an executable work) run the object code and to modify the work, including scripts to control those activities.
|
||||
However, it does not include the work's System Libraries, or general-purpose tools or generally available free programs
|
||||
which are used unmodified in performing those activities but which are not part of the work. For example, Corresponding
|
||||
Source includes interface definition files associated with source files for the work, and the source code for shared libraries
|
||||
and dynamically linked subprograms that the work is specifically designed to require, such as by intimate data communication
|
||||
or control flow between those subprograms and other parts of the work.</p>
|
||||
|
||||
<p>The Corresponding Source need not include anything that users can regenerate automatically from other parts of the Corresponding
|
||||
Source.
|
||||
</p>
|
||||
|
||||
<p>The Corresponding Source for a work in source code form is that same work.</p>
|
||||
|
||||
<h4>
|
||||
<a name="section2"></a>2. Basic Permissions.</h4>
|
||||
|
||||
<p>All rights granted under this License are granted for the term of copyright on the Program, and are irrevocable provided
|
||||
the stated conditions are met. This License explicitly affirms your unlimited permission to run the unmodified Program.
|
||||
The output from running a covered work is covered by this License only if the output, given its content, constitutes a
|
||||
covered work. This License acknowledges your rights of fair use or other equivalent, as provided by copyright law.</p>
|
||||
|
||||
<p>You may make, run and propagate covered works that you do not convey, without conditions so long as your license otherwise
|
||||
remains in force. You may convey covered works to others for the sole purpose of having them make modifications exclusively
|
||||
for you, or provide you with facilities for running those works, provided that you comply with the terms of this License
|
||||
in conveying all material for which you do not control copyright. Those thus making or running the covered works for you
|
||||
must do so exclusively on your behalf, under your direction and control, on terms that prohibit them from making any copies
|
||||
of your copyrighted material outside their relationship with you.</p>
|
||||
|
||||
<p>Conveying under any other circumstances is permitted solely under the conditions stated below. Sublicensing is not allowed;
|
||||
section 10 makes it unnecessary.</p>
|
||||
|
||||
<h4>
|
||||
<a name="section3"></a>3. Protecting Users' Legal Rights From Anti-Circumvention Law.</h4>
|
||||
|
||||
<p>No covered work shall be deemed part of an effective technological measure under any applicable law fulfilling obligations
|
||||
under article 11 of the WIPO copyright treaty adopted on 20 December 1996, or similar laws prohibiting or restricting
|
||||
circumvention of such measures.
|
||||
</p>
|
||||
|
||||
<p>When you convey a covered work, you waive any legal power to forbid circumvention of technological measures to the extent
|
||||
such circumvention is effected by exercising rights under this License with respect to the covered work, and you disclaim
|
||||
any intention to limit operation or modification of the work as a means of enforcing, against the work's users, your or
|
||||
third parties' legal rights to forbid circumvention of technological measures.</p>
|
||||
|
||||
<h4>
|
||||
<a name="section4"></a>4. Conveying Verbatim Copies.</h4>
|
||||
|
||||
<p>You may convey verbatim copies of the Program's source code as you receive it, in any medium, provided that you conspicuously
|
||||
and appropriately publish on each copy an appropriate copyright notice; keep intact all notices stating that this License
|
||||
and any non-permissive terms added in accord with section 7 apply to the code; keep intact all notices of the absence
|
||||
of any warranty; and give all recipients a copy of this License along with the Program.</p>
|
||||
|
||||
<p>You may charge any price or no price for each copy that you convey, and you may offer support or warranty protection for
|
||||
a fee.</p>
|
||||
|
||||
<h4>
|
||||
<a name="section5"></a>5. Conveying Modified Source Versions.</h4>
|
||||
|
||||
<p>You may convey a work based on the Program, or the modifications to produce it from the Program, in the form of source
|
||||
code under the terms of section 4, provided that you also meet all of these conditions:</p>
|
||||
|
||||
<ul>
|
||||
<li>a) The work must carry prominent notices stating that you modified it, and giving a relevant date.
|
||||
</li>
|
||||
|
||||
<li>b) The work must carry prominent notices stating that it is released under this License and any conditions added under
|
||||
section 7. This requirement modifies the requirement in section 4 to “keep intact all notices”.
|
||||
</li>
|
||||
|
||||
<li>c) You must license the entire work, as a whole, under this License to anyone who comes into possession of a copy. This
|
||||
License will therefore apply, along with any applicable section 7 additional terms, to the whole of the work, and all
|
||||
its parts, regardless of how they are packaged. This License gives no permission to license the work in any other way,
|
||||
but it does not invalidate such permission if you have separately received it.
|
||||
</li>
|
||||
|
||||
<li>d) If the work has interactive user interfaces, each must display Appropriate Legal Notices; however, if the Program has
|
||||
interactive interfaces that do not display Appropriate Legal Notices, your work need not make them do so.
|
||||
</li>
|
||||
</ul>
|
||||
|
||||
<p>A compilation of a covered work with other separate and independent works, which are not by their nature extensions of
|
||||
the covered work, and which are not combined with it such as to form a larger program, in or on a volume of a storage
|
||||
or distribution medium, is called an “aggregate” if the compilation and its resulting copyright are not used
|
||||
to limit the access or legal rights of the compilation's users beyond what the individual works permit. Inclusion of a
|
||||
covered work in an aggregate does not cause this License to apply to the other parts of the aggregate.</p>
|
||||
|
||||
<h4>
|
||||
<a name="section6"></a>6. Conveying Non-Source Forms.</h4>
|
||||
|
||||
<p>You may convey a covered work in object code form under the terms of sections 4 and 5, provided that you also convey the
|
||||
machine-readable Corresponding Source under the terms of this License, in one of these ways:</p>
|
||||
|
||||
<ul>
|
||||
<li>a) Convey the object code in, or embodied in, a physical product (including a physical distribution medium), accompanied
|
||||
by the Corresponding Source fixed on a durable physical medium customarily used for software interchange.
|
||||
</li>
|
||||
|
||||
<li>b) Convey the object code in, or embodied in, a physical product (including a physical distribution medium), accompanied
|
||||
by a written offer, valid for at least three years and valid for as long as you offer spare parts or customer support
|
||||
for that product model, to give anyone who possesses the object code either (1) a copy of the Corresponding Source for
|
||||
all the software in the product that is covered by this License, on a durable physical medium customarily used for software
|
||||
interchange, for a price no more than your reasonable cost of physically performing this conveying of source, or (2)
|
||||
access to copy the Corresponding Source from a network server at no charge.
|
||||
</li>
|
||||
|
||||
<li>c) Convey individual copies of the object code with a copy of the written offer to provide the Corresponding Source. This
|
||||
alternative is allowed only occasionally and noncommercially, and only if you received the object code with such an offer,
|
||||
in accord with subsection 6b.
|
||||
</li>
|
||||
|
||||
<li>d) Convey the object code by offering access from a designated place (gratis or for a charge), and offer equivalent access
|
||||
to the Corresponding Source in the same way through the same place at no further charge. You need not require recipients
|
||||
to copy the Corresponding Source along with the object code. If the place to copy the object code is a network server,
|
||||
the Corresponding Source may be on a different server (operated by you or a third party) that supports equivalent copying
|
||||
facilities, provided you maintain clear directions next to the object code saying where to find the Corresponding Source.
|
||||
Regardless of what server hosts the Corresponding Source, you remain obligated to ensure that it is available for as
|
||||
long as needed to satisfy these requirements.
|
||||
</li>
|
||||
|
||||
<li>e) Convey the object code using peer-to-peer transmission, provided you inform other peers where the object code and Corresponding
|
||||
Source of the work are being offered to the general public at no charge under subsection 6d.
|
||||
</li>
|
||||
</ul>
|
||||
|
||||
<p>A separable portion of the object code, whose source code is excluded from the Corresponding Source as a System Library,
|
||||
need not be included in conveying the object code work.</p>
|
||||
|
||||
<p>A “User Product” is either (1) a “consumer product”, which means any tangible personal property
|
||||
which is normally used for personal, family, or household purposes, or (2) anything designed or sold for incorporation
|
||||
into a dwelling. In determining whether a product is a consumer product, doubtful cases shall be resolved in favor of
|
||||
coverage. For a particular product received by a particular user, “normally used” refers to a typical or common
|
||||
use of that class of product, regardless of the status of the particular user or of the way in which the particular user
|
||||
actually uses, or expects or is expected to use, the product. A product is a consumer product regardless of whether the
|
||||
product has substantial commercial, industrial or non-consumer uses, unless such uses represent the only significant mode
|
||||
of use of the product.</p>
|
||||
|
||||
<p>“Installation Information” for a User Product means any methods, procedures, authorization keys, or other information
|
||||
required to install and execute modified versions of a covered work in that User Product from a modified version of its
|
||||
Corresponding Source. The information must suffice to ensure that the continued functioning of the modified object code
|
||||
is in no case prevented or interfered with solely because modification has been made.</p>
|
||||
|
||||
<p>If you convey an object code work under this section in, or with, or specifically for use in, a User Product, and the conveying
|
||||
occurs as part of a transaction in which the right of possession and use of the User Product is transferred to the recipient
|
||||
in perpetuity or for a fixed term (regardless of how the transaction is characterized), the Corresponding Source conveyed
|
||||
under this section must be accompanied by the Installation Information. But this requirement does not apply if neither
|
||||
you nor any third party retains the ability to install modified object code on the User Product (for example, the work
|
||||
has been installed in ROM).</p>
|
||||
|
||||
<p>The requirement to provide Installation Information does not include a requirement to continue to provide support service,
|
||||
warranty, or updates for a work that has been modified or installed by the recipient, or for the User Product in which
|
||||
it has been modified or installed. Access to a network may be denied when the modification itself materially and adversely
|
||||
affects the operation of the network or violates the rules and protocols for communication across the network.</p>
|
||||
|
||||
<p>Corresponding Source conveyed, and Installation Information provided, in accord with this section must be in a format that
|
||||
is publicly documented (and with an implementation available to the public in source code form), and must require no special
|
||||
password or key for unpacking, reading or copying.</p>
|
||||
|
||||
<h4>
|
||||
<a name="section7"></a>7. Additional Terms.</h4>
|
||||
|
||||
<p>“Additional permissions” are terms that supplement the terms of this License by making exceptions from one
|
||||
or more of its conditions. Additional permissions that are applicable to the entire Program shall be treated as though
|
||||
they were included in this License, to the extent that they are valid under applicable law. If additional permissions
|
||||
apply only to part of the Program, that part may be used separately under those permissions, but the entire Program remains
|
||||
governed by this License without regard to the additional permissions.</p>
|
||||
|
||||
<p>When you convey a copy of a covered work, you may at your option remove any additional permissions from that copy, or from
|
||||
any part of it. (Additional permissions may be written to require their own removal in certain cases when you modify the
|
||||
work.) You may place additional permissions on material, added by you to a covered work, for which you have or can give
|
||||
appropriate copyright permission.</p>
|
||||
|
||||
<p>Notwithstanding any other provision of this License, for material you add to a covered work, you may (if authorized by
|
||||
the copyright holders of that material) supplement the terms of this License with terms:</p>
|
||||
|
||||
<ul>
|
||||
<li>a) Disclaiming warranty or limiting liability differently from the terms of sections 15 and 16 of this License; or
|
||||
</li>
|
||||
|
||||
<li>b) Requiring preservation of specified reasonable legal notices or author attributions in that material or in the Appropriate
|
||||
Legal Notices displayed by works containing it; or
|
||||
</li>
|
||||
|
||||
<li>c) Prohibiting misrepresentation of the origin of that material, or requiring that modified versions of such material
|
||||
be marked in reasonable ways as different from the original version; or
|
||||
</li>
|
||||
|
||||
<li>d) Limiting the use for publicity purposes of names of licensors or authors of the material; or
|
||||
</li>
|
||||
|
||||
<li>e) Declining to grant rights under trademark law for use of some trade names, trademarks, or service marks; or
|
||||
</li>
|
||||
|
||||
<li>f) Requiring indemnification of licensors and authors of that material by anyone who conveys the material (or modified
|
||||
versions of it) with contractual assumptions of liability to the recipient, for any liability that these contractual
|
||||
assumptions directly impose on those licensors and authors.
|
||||
</li>
|
||||
</ul>
|
||||
|
||||
<p>All other non-permissive additional terms are considered “further restrictions” within the meaning of section
|
||||
10. If the Program as you received it, or any part of it, contains a notice stating that it is governed by this License
|
||||
along with a term that is a further restriction, you may remove that term. If a license document contains a further restriction
|
||||
but permits relicensing or conveying under this License, you may add to a covered work material governed by the terms
|
||||
of that license document, provided that the further restriction does not survive such relicensing or conveying.</p>
|
||||
|
||||
<p>If you add terms to a covered work in accord with this section, you must place, in the relevant source files, a statement
|
||||
of the additional terms that apply to those files, or a notice indicating where to find the applicable terms.</p>
|
||||
|
||||
<p>Additional terms, permissive or non-permissive, may be stated in the form of a separately written license, or stated as
|
||||
exceptions; the above requirements apply either way.</p>
|
||||
|
||||
<h4>
|
||||
<a name="section8"></a>8. Termination.</h4>
|
||||
|
||||
<p>You may not propagate or modify a covered work except as expressly provided under this License. Any attempt otherwise to
|
||||
propagate or modify it is void, and will automatically terminate your rights under this License (including any patent
|
||||
licenses granted under the third paragraph of section 11).</p>
|
||||
|
||||
<p>However, if you cease all violation of this License, then your license from a particular copyright holder is reinstated
|
||||
(a) provisionally, unless and until the copyright holder explicitly and finally terminates your license, and (b) permanently,
|
||||
if the copyright holder fails to notify you of the violation by some reasonable means prior to 60 days after the cessation.</p>
|
||||
|
||||
<p>Moreover, your license from a particular copyright holder is reinstated permanently if the copyright holder notifies you
|
||||
of the violation by some reasonable means, this is the first time you have received notice of violation of this License
|
||||
(for any work) from that copyright holder, and you cure the violation prior to 30 days after your receipt of the notice.</p>
|
||||
|
||||
<p>Termination of your rights under this section does not terminate the licenses of parties who have received copies or rights
|
||||
from you under this License. If your rights have been terminated and not permanently reinstated, you do not qualify to
|
||||
receive new licenses for the same material under section 10.</p>
|
||||
|
||||
<h4>
|
||||
<a name="section9"></a>9. Acceptance Not Required for Having Copies.</h4>
|
||||
|
||||
<p>You are not required to accept this License in order to receive or run a copy of the Program. Ancillary propagation of
|
||||
a covered work occurring solely as a consequence of using peer-to-peer transmission to receive a copy likewise does not
|
||||
require acceptance. However, nothing other than this License grants you permission to propagate or modify any covered
|
||||
work. These actions infringe copyright if you do not accept this License. Therefore, by modifying or propagating a covered
|
||||
work, you indicate your acceptance of this License to do so.</p>
|
||||
|
||||
<h4>
|
||||
<a name="section10"></a>10. Automatic Licensing of Downstream Recipients.</h4>
|
||||
|
||||
<p>Each time you convey a covered work, the recipient automatically receives a license from the original licensors, to run,
|
||||
modify and propagate that work, subject to this License. You are not responsible for enforcing compliance by third parties
|
||||
with this License.</p>
|
||||
|
||||
<p>An “entity transaction” is a transaction transferring control of an organization, or substantially all assets
|
||||
of one, or subdividing an organization, or merging organizations. If propagation of a covered work results from an entity
|
||||
transaction, each party to that transaction who receives a copy of the work also receives whatever licenses to the work
|
||||
the party's predecessor in interest had or could give under the previous paragraph, plus a right to possession of the
|
||||
Corresponding Source of the work from the predecessor in interest, if the predecessor has it or can get it with reasonable
|
||||
efforts.
|
||||
</p>
|
||||
|
||||
<p>You may not impose any further restrictions on the exercise of the rights granted or affirmed under this License. For example,
|
||||
you may not impose a license fee, royalty, or other charge for exercise of rights granted under this License, and you
|
||||
may not initiate litigation (including a cross-claim or counterclaim in a lawsuit) alleging that any patent claim is infringed
|
||||
by making, using, selling, offering for sale, or importing the Program or any portion of it.</p>
|
||||
|
||||
<h4>
|
||||
<a name="section11"></a>11. Patents.</h4>
|
||||
|
||||
<p>A “contributor” is a copyright holder who authorizes use under this License of the Program or a work on which
|
||||
the Program is based. The work thus licensed is called the contributor's “contributor version”.</p>
|
||||
|
||||
<p>A contributor's “essential patent claims” are all patent claims owned or controlled by the contributor, whether
|
||||
already acquired or hereafter acquired, that would be infringed by some manner, permitted by this License, of making,
|
||||
using, or selling its contributor version, but do not include claims that would be infringed only as a consequence of
|
||||
further modification of the contributor version. For purposes of this definition, “control” includes the right
|
||||
to grant patent sublicenses in a manner consistent with the requirements of this License.</p>
|
||||
|
||||
<p>Each contributor grants you a non-exclusive, worldwide, royalty-free patent license under the contributor's essential patent
|
||||
claims, to make, use, sell, offer for sale, import and otherwise run, modify and propagate the contents of its contributor
|
||||
version.
|
||||
</p>
|
||||
|
||||
<p>In the following three paragraphs, a “patent license” is any express agreement or commitment, however denominated,
|
||||
not to enforce a patent (such as an express permission to practice a patent or covenant not to sue for patent infringement).
|
||||
To “grant” such a patent license to a party means to make such an agreement or commitment not to enforce a
|
||||
patent against the party.</p>
|
||||
|
||||
<p>If you convey a covered work, knowingly relying on a patent license, and the Corresponding Source of the work is not available
|
||||
for anyone to copy, free of charge and under the terms of this License, through a publicly available network server or
|
||||
other readily accessible means, then you must either (1) cause the Corresponding Source to be so available, or (2) arrange
|
||||
to deprive yourself of the benefit of the patent license for this particular work, or (3) arrange, in a manner consistent
|
||||
with the requirements of this License, to extend the patent license to downstream recipients. “Knowingly relying”
|
||||
means you have actual knowledge that, but for the patent license, your conveying the covered work in a country, or your
|
||||
recipient's use of the covered work in a country, would infringe one or more identifiable patents in that country that
|
||||
you have reason to believe are valid.</p>
|
||||
|
||||
<p>If, pursuant to or in connection with a single transaction or arrangement, you convey, or propagate by procuring conveyance
|
||||
of, a covered work, and grant a patent license to some of the parties receiving the covered work authorizing them to use,
|
||||
propagate, modify or convey a specific copy of the covered work, then the patent license you grant is automatically extended
|
||||
to all recipients of the covered work and works based on it.</p>
|
||||
|
||||
<p>A patent license is “discriminatory” if it does not include within the scope of its coverage, prohibits the
|
||||
exercise of, or is conditioned on the non-exercise of one or more of the rights that are specifically granted under this
|
||||
License. You may not convey a covered work if you are a party to an arrangement with a third party that is in the business
|
||||
of distributing software, under which you make payment to the third party based on the extent of your activity of conveying
|
||||
the work, and under which the third party grants, to any of the parties who would receive the covered work from you, a
|
||||
discriminatory patent license (a) in connection with copies of the covered work conveyed by you (or copies made from those
|
||||
copies), or (b) primarily for and in connection with specific products or compilations that contain the covered work,
|
||||
unless you entered into that arrangement, or that patent license was granted, prior to 28 March 2007.</p>
|
||||
|
||||
<p>Nothing in this License shall be construed as excluding or limiting any implied license or other defenses to infringement
|
||||
that may otherwise be available to you under applicable patent law.</p>
|
||||
|
||||
<h4>
|
||||
<a name="section12"></a>12. No Surrender of Others' Freedom.</h4>
|
||||
|
||||
<p>If conditions are imposed on you (whether by court order, agreement or otherwise) that contradict the conditions of this
|
||||
License, they do not excuse you from the conditions of this License. If you cannot convey a covered work so as to satisfy
|
||||
simultaneously your obligations under this License and any other pertinent obligations, then as a consequence you may
|
||||
not convey it at all. For example, if you agree to terms that obligate you to collect a royalty for further conveying
|
||||
from those to whom you convey the Program, the only way you could satisfy both those terms and this License would be to
|
||||
refrain entirely from conveying the Program.</p>
|
||||
|
||||
<h4>
|
||||
<a name="section13"></a>13. Use with the GNU Affero General Public License.</h4>
|
||||
|
||||
<p>Notwithstanding any other provision of this License, you have permission to link or combine any covered work with a work
|
||||
licensed under version 3 of the GNU Affero General Public License into a single combined work, and to convey the resulting
|
||||
work. The terms of this License will continue to apply to the part which is the covered work, but the special requirements
|
||||
of the GNU Affero General Public License, section 13, concerning interaction through a network will apply to the combination
|
||||
as such.</p>
|
||||
|
||||
<h4>
|
||||
<a name="section14"></a>14. Revised Versions of this License.</h4>
|
||||
|
||||
<p>The Free Software Foundation may publish revised and/or new versions of the GNU General Public License from time to time.
|
||||
Such new versions will be similar in spirit to the present version, but may differ in detail to address new problems or
|
||||
concerns.
|
||||
</p>
|
||||
|
||||
<p>Each version is given a distinguishing version number. If the Program specifies that a certain numbered version of the
|
||||
GNU General Public License “or any later version” applies to it, you have the option of following the terms
|
||||
and conditions either of that numbered version or of any later version published by the Free Software Foundation. If the
|
||||
Program does not specify a version number of the GNU General Public License, you may choose any version ever published
|
||||
by the Free Software Foundation.</p>
|
||||
|
||||
<p>If the Program specifies that a proxy can decide which future versions of the GNU General Public License can be used, that
|
||||
proxy's public statement of acceptance of a version permanently authorizes you to choose that version for the Program.</p>
|
||||
|
||||
<p>Later license versions may give you additional or different permissions. However, no additional obligations are imposed
|
||||
on any author or copyright holder as a result of your choosing to follow a later version.</p>
|
||||
|
||||
<h4>
|
||||
<a name="section15"></a>15. Disclaimer of Warranty.</h4>
|
||||
|
||||
<p>THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING
|
||||
THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM “AS IS” WITHOUT WARRANTY OF ANY KIND, EITHER
|
||||
EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||
PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE,
|
||||
YOU ASSUME THE COST OF ALL NECESSARY SERVICING, REPAIR OR CORRECTION.</p>
|
||||
|
||||
<h4>
|
||||
<a name="section16"></a>16. Limitation of Liability.</h4>
|
||||
|
||||
<p>IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO
|
||||
MODIFIES AND/OR CONVEYS THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL,
|
||||
INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED
|
||||
TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM
|
||||
TO OPERATE WITH ANY OTHER PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.</p>
|
||||
|
||||
<h4>
|
||||
<a name="section17"></a>17. Interpretation of Sections 15 and 16.</h4>
|
||||
|
||||
<p>If the disclaimer of warranty and limitation of liability provided above cannot be given local legal effect according to
|
||||
their terms, reviewing courts shall apply local law that most closely approximates an absolute waiver of all civil liability
|
||||
in connection with the Program, unless a warranty or assumption of liability accompanies a copy of the Program in return
|
||||
for a fee.</p>
|
||||
</div>
|
||||
<p><a href="#top">Back to the top</a></p>
|
||||
|
||||
<h3 id="xiph">Xiph.org BSD-like license</h3>
|
||||
|
||||
<p>Copyright (C) 2000,2001,2002,2003,2004,2005,2006,2007 Josh Coalson</p>
|
||||
|
||||
<p>
|
||||
Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following
|
||||
conditions are met:
|
||||
|
||||
<ul>
|
||||
<li>Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
|
||||
</li>
|
||||
<li>Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer
|
||||
in the documentation and/or other materials provided with the distribution.
|
||||
</li>
|
||||
<li>Neither the name of the Xiph.org Foundation nor the names of its contributors may be used to endorse or promote products
|
||||
derived from this software without specific prior written permission.
|
||||
</li>
|
||||
</ul>
|
||||
|
||||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING,
|
||||
BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO
|
||||
EVENT SHALL THE FOUNDATION OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
|
||||
BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
||||
NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
|
||||
DAMAGE.
|
||||
</p>
|
||||
<p><a href="#top">Back to the top</a></p>
|
||||
</body>
|
||||
|
||||
</html>
|
|
@ -1,47 +0,0 @@
|
|||
/*
|
||||
* This file is part of snapcast
|
||||
* Copyright (C) 2014-2017 Johannes Pohl
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package de.badaix.snapcast;
|
||||
|
||||
import android.content.pm.PackageInfo;
|
||||
import android.content.pm.PackageManager;
|
||||
import android.os.Bundle;
|
||||
import android.support.v7.app.AppCompatActivity;
|
||||
import android.webkit.WebView;
|
||||
|
||||
public class AboutActivity extends AppCompatActivity {
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
setContentView(R.layout.activity_about);
|
||||
try {
|
||||
getSupportActionBar().setTitle(getString(R.string.about) + " Snapcast");
|
||||
} catch (Exception e) {
|
||||
}
|
||||
PackageInfo pInfo;
|
||||
try {
|
||||
pInfo = getPackageManager().getPackageInfo(getPackageName(), 0);
|
||||
getSupportActionBar().setSubtitle("v" + pInfo.versionName);
|
||||
} catch (PackageManager.NameNotFoundException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
WebView wv = (WebView) findViewById(R.id.webView);
|
||||
wv.loadUrl("file:///android_asset/" + this.getText(R.string.about_file));
|
||||
}
|
||||
}
|
|
@ -1,53 +0,0 @@
|
|||
/*
|
||||
* This file is part of snapcast
|
||||
* Copyright (C) 2014-2017 Johannes Pohl
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package de.badaix.snapcast;
|
||||
|
||||
import android.content.BroadcastReceiver;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.text.TextUtils;
|
||||
|
||||
import de.badaix.snapcast.utils.Settings;
|
||||
|
||||
/**
|
||||
* Created by johannes on 05.05.16.
|
||||
*/
|
||||
public class BootCompleteReceiver extends BroadcastReceiver {
|
||||
@Override
|
||||
public void onReceive(Context context, Intent intent) {
|
||||
if ("android.intent.action.BOOT_COMPLETED".equals(intent.getAction())) {
|
||||
if (Settings.getInstance(context).isAutostart()) {
|
||||
String host = Settings.getInstance(context).getHost();
|
||||
int port = Settings.getInstance(context).getStreamPort();
|
||||
if (TextUtils.isEmpty(host))
|
||||
return;
|
||||
|
||||
Intent i = new Intent(context, SnapclientService.class);
|
||||
i.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_SINGLE_TOP);
|
||||
i.putExtra(SnapclientService.EXTRA_HOST, host);
|
||||
i.putExtra(SnapclientService.EXTRA_PORT, port);
|
||||
i.setAction(SnapclientService.ACTION_START);
|
||||
|
||||
context.startService(i);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -1,148 +0,0 @@
|
|||
/*
|
||||
* This file is part of snapcast
|
||||
* Copyright (C) 2014-2017 Johannes Pohl
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package de.badaix.snapcast;
|
||||
|
||||
import android.content.Context;
|
||||
import android.support.v7.widget.PopupMenu;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.Menu;
|
||||
import android.view.MenuItem;
|
||||
import android.view.View;
|
||||
import android.widget.ImageButton;
|
||||
import android.widget.LinearLayout;
|
||||
import android.widget.SeekBar;
|
||||
import android.widget.TextView;
|
||||
|
||||
import de.badaix.snapcast.control.json.Client;
|
||||
import de.badaix.snapcast.control.json.Volume;
|
||||
|
||||
public class ClientItem extends LinearLayout implements SeekBar.OnSeekBarChangeListener, View.OnClickListener, PopupMenu.OnMenuItemClickListener {
|
||||
|
||||
private static final String TAG = "ClientItem";
|
||||
|
||||
private TextView title;
|
||||
private SeekBar volumeSeekBar;
|
||||
private ImageButton ibMute;
|
||||
private ImageButton ibOverflow;
|
||||
private Client client;
|
||||
private ClientItemListener listener = null;
|
||||
|
||||
public ClientItem(Context context) {
|
||||
this(context, null);
|
||||
}
|
||||
|
||||
public ClientItem(Context context, Client client) {
|
||||
super(context);
|
||||
LayoutInflater vi = (LayoutInflater) context
|
||||
.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
|
||||
vi.inflate(R.layout.client_item, this);
|
||||
title = (TextView) findViewById(R.id.title);
|
||||
volumeSeekBar = (SeekBar) findViewById(R.id.volumeSeekBar);
|
||||
ibMute = (ImageButton) findViewById(R.id.ibMute);
|
||||
ibMute.setImageResource(R.drawable.ic_speaker_icon);
|
||||
ibMute.setOnClickListener(this);
|
||||
ibOverflow = (ImageButton) findViewById(R.id.ibOverflow);
|
||||
ibOverflow.setOnClickListener(this);
|
||||
volumeSeekBar.setOnSeekBarChangeListener(this);
|
||||
setClient(client);
|
||||
}
|
||||
|
||||
public void update() {
|
||||
//Log.d(TAG, "update: " + client.getVisibleName() + ", connected: " + client.isConnected());
|
||||
title.setText(client.getVisibleName());
|
||||
title.setEnabled(client.isConnected());
|
||||
volumeSeekBar.setProgress(client.getConfig().getVolume().getPercent());
|
||||
if (client.getConfig().getVolume().isMuted())
|
||||
ibMute.setImageResource(R.drawable.ic_mute_icon);
|
||||
else
|
||||
ibMute.setImageResource(R.drawable.ic_speaker_icon);
|
||||
}
|
||||
|
||||
public Client getClient() {
|
||||
return client;
|
||||
}
|
||||
|
||||
public void setClient(final Client client) {
|
||||
this.client = client;
|
||||
update();
|
||||
}
|
||||
|
||||
public void setListener(ClientItemListener listener) {
|
||||
this.listener = listener;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
|
||||
if (fromUser && (listener != null)) {
|
||||
Volume volume = client.getConfig().getVolume();
|
||||
volume.setPercent(progress);
|
||||
listener.onVolumeChanged(this, volume.getPercent(), volume.isMuted());
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
if (v == ibMute) {
|
||||
Volume volume = client.getConfig().getVolume();
|
||||
volume.setMuted(!volume.isMuted());
|
||||
update();
|
||||
listener.onVolumeChanged(this, volume.getPercent(), volume.isMuted());
|
||||
} else if (v == ibOverflow) {
|
||||
PopupMenu popup = new PopupMenu(v.getContext(), v);
|
||||
popup.getMenu().add(Menu.NONE, R.id.menu_details, 0, R.string.menu_details);
|
||||
if (!client.isConnected())
|
||||
popup.getMenu().add(Menu.NONE, R.id.menu_delete, 1, R.string.menu_delete);
|
||||
popup.setOnMenuItemClickListener(this);
|
||||
popup.show();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onStartTrackingTouch(SeekBar seekBar) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onStopTrackingTouch(SeekBar seekBar) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onMenuItemClick(MenuItem item) {
|
||||
switch (item.getItemId()) {
|
||||
case R.id.menu_details:
|
||||
listener.onPropertiesClicked(this);
|
||||
return true;
|
||||
case R.id.menu_delete:
|
||||
listener.onDeleteClicked(this);
|
||||
return true;
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
public interface ClientItemListener {
|
||||
void onVolumeChanged(ClientItem clientItem, int percent, boolean mute);
|
||||
|
||||
void onDeleteClicked(ClientItem clientItem);
|
||||
|
||||
void onPropertiesClicked(ClientItem clientItem);
|
||||
}
|
||||
|
||||
}
|
|
@ -1,63 +0,0 @@
|
|||
/*
|
||||
* This file is part of snapcast
|
||||
* Copyright (C) 2014-2017 Johannes Pohl
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package de.badaix.snapcast;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.content.Intent;
|
||||
import android.os.Bundle;
|
||||
import android.support.v7.app.AppCompatActivity;
|
||||
import android.view.MenuItem;
|
||||
|
||||
/**
|
||||
* Created by johannes on 11.01.16.
|
||||
*/
|
||||
public class ClientSettingsActivity extends AppCompatActivity {
|
||||
private ClientSettingsFragment clientSettingsFragment = null;
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
clientSettingsFragment = new ClientSettingsFragment();
|
||||
clientSettingsFragment.setArguments(getIntent().getExtras());
|
||||
|
||||
// Display the fragment as the main content.
|
||||
getFragmentManager().beginTransaction()
|
||||
.replace(android.R.id.content, clientSettingsFragment)
|
||||
.commit();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onOptionsItemSelected(MenuItem item) {
|
||||
if (item.getItemId() == android.R.id.home) {
|
||||
onBackPressed();
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onBackPressed() {
|
||||
Intent intent = new Intent();
|
||||
intent.putExtra("client", clientSettingsFragment.getClient().toJson().toString());
|
||||
intent.putExtra("clientOriginal", clientSettingsFragment.getOriginalClientInfo().toJson().toString());
|
||||
setResult(Activity.RESULT_OK, intent);
|
||||
finish();
|
||||
// super.onBackPressed();
|
||||
}
|
||||
}
|
|
@ -1,124 +0,0 @@
|
|||
/*
|
||||
* This file is part of snapcast
|
||||
* Copyright (C) 2014-2017 Johannes Pohl
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package de.badaix.snapcast;
|
||||
|
||||
import android.os.Bundle;
|
||||
import android.preference.EditTextPreference;
|
||||
import android.preference.Preference;
|
||||
import android.preference.PreferenceFragment;
|
||||
import android.text.TextUtils;
|
||||
import android.text.format.DateUtils;
|
||||
|
||||
import org.json.JSONException;
|
||||
import org.json.JSONObject;
|
||||
|
||||
import de.badaix.snapcast.control.json.Client;
|
||||
|
||||
/**
|
||||
* Created by johannes on 11.01.16.
|
||||
*/
|
||||
public class ClientSettingsFragment extends PreferenceFragment {
|
||||
private Client client = null;
|
||||
private Client clientOriginal = null;
|
||||
private EditTextPreference prefName;
|
||||
private EditTextPreference prefLatency;
|
||||
private Preference prefMac;
|
||||
private Preference prefId;
|
||||
private Preference prefIp;
|
||||
private Preference prefHost;
|
||||
private Preference prefOS;
|
||||
private Preference prefVersion;
|
||||
private Preference prefLastSeen;
|
||||
|
||||
|
||||
@Override
|
||||
public void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
|
||||
Bundle bundle = getArguments();
|
||||
try {
|
||||
client = new Client(new JSONObject(bundle.getString("client")));
|
||||
} catch (JSONException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
clientOriginal = new Client(client.toJson());
|
||||
|
||||
// Load the preferences from an XML resource
|
||||
addPreferencesFromResource(R.xml.client_preferences);
|
||||
prefName = (EditTextPreference) findPreference("pref_client_name");
|
||||
prefName.setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() {
|
||||
@Override
|
||||
public boolean onPreferenceChange(Preference preference, Object newValue) {
|
||||
prefName.setSummary((String) newValue);
|
||||
client.setName((String) newValue);
|
||||
return true;
|
||||
}
|
||||
});
|
||||
|
||||
prefMac = (Preference) findPreference("pref_client_mac");
|
||||
prefId = (Preference) findPreference("pref_client_id");
|
||||
prefIp = (Preference) findPreference("pref_client_ip");
|
||||
prefHost = (Preference) findPreference("pref_client_host");
|
||||
prefOS = (Preference) findPreference("pref_client_os");
|
||||
prefVersion = (Preference) findPreference("pref_client_version");
|
||||
prefLastSeen = (Preference) findPreference("pref_client_last_seen");
|
||||
prefLatency = (EditTextPreference) findPreference("pref_client_latency");
|
||||
prefLatency.setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() {
|
||||
@Override
|
||||
public boolean onPreferenceChange(Preference preference, Object newValue) {
|
||||
String latency = (String) newValue;
|
||||
if (TextUtils.isEmpty(latency))
|
||||
latency = "0";
|
||||
prefLatency.setSummary(latency + "ms");
|
||||
client.getConfig().setLatency(Integer.parseInt(latency));
|
||||
return true;
|
||||
}
|
||||
});
|
||||
update();
|
||||
}
|
||||
|
||||
public Client getClient() {
|
||||
return client;
|
||||
}
|
||||
|
||||
public Client getOriginalClientInfo() {
|
||||
return clientOriginal;
|
||||
}
|
||||
|
||||
public void update() {
|
||||
if (client == null)
|
||||
return;
|
||||
prefName.setSummary(client.getConfig().getName());
|
||||
prefName.setText(client.getConfig().getName());
|
||||
prefMac.setSummary(client.getHost().getMac());
|
||||
prefId.setSummary(client.getId());
|
||||
prefIp.setSummary(client.getHost().getIp());
|
||||
prefHost.setSummary(client.getHost().getName());
|
||||
prefOS.setSummary(client.getHost().getOs() + "@" + client.getHost().getArch());
|
||||
prefVersion.setSummary(client.getSnapclient().getVersion());
|
||||
String lastSeen = getText(R.string.online).toString();
|
||||
if (!client.isConnected()) {
|
||||
long lastSeenTs = Math.min(client.getLastSeen().getSec() * 1000, System.currentTimeMillis());
|
||||
lastSeen = DateUtils.getRelativeTimeSpanString(lastSeenTs, System.currentTimeMillis(), DateUtils.SECOND_IN_MILLIS).toString();
|
||||
}
|
||||
prefLastSeen.setSummary(lastSeen);
|
||||
prefLatency.setSummary(client.getConfig().getLatency() + "ms");
|
||||
prefLatency.setText(client.getConfig().getLatency() + "");
|
||||
}
|
||||
}
|
|
@ -1,260 +0,0 @@
|
|||
/*
|
||||
* This file is part of snapcast
|
||||
* Copyright (C) 2014-2017 Johannes Pohl
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package de.badaix.snapcast;
|
||||
|
||||
import android.content.Context;
|
||||
import android.util.Log;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.MotionEvent;
|
||||
import android.view.View;
|
||||
import android.widget.ImageButton;
|
||||
import android.widget.LinearLayout;
|
||||
import android.widget.SeekBar;
|
||||
import android.widget.TextView;
|
||||
|
||||
import java.util.Vector;
|
||||
|
||||
import de.badaix.snapcast.control.json.Client;
|
||||
import de.badaix.snapcast.control.json.Group;
|
||||
import de.badaix.snapcast.control.json.ServerStatus;
|
||||
import de.badaix.snapcast.control.json.Stream;
|
||||
import de.badaix.snapcast.control.json.Volume;
|
||||
|
||||
/**
|
||||
* Created by johannes on 04.12.16.
|
||||
*/
|
||||
|
||||
|
||||
public class GroupItem extends LinearLayout implements SeekBar.OnSeekBarChangeListener, View.OnClickListener, ClientItem.ClientItemListener, View.OnTouchListener {
|
||||
|
||||
private static final String TAG = "GroupItem";
|
||||
|
||||
// private TextView title;
|
||||
private SeekBar volumeSeekBar;
|
||||
private ImageButton ibMute;
|
||||
private ImageButton ibSettings;
|
||||
private LinearLayout llClient;
|
||||
private Group group;
|
||||
private ServerStatus server;
|
||||
private TextView tvStreamName = null;
|
||||
private GroupItemListener listener = null;
|
||||
private LinearLayout llVolume;
|
||||
private boolean hideOffline = false;
|
||||
private Vector<ClientItem> clientItems = null;
|
||||
private Vector<Integer> clientVolumes = null;
|
||||
private int groupVolume = 0;
|
||||
|
||||
public GroupItem(Context context, ServerStatus server, Group group) {
|
||||
super(context);
|
||||
LayoutInflater vi = (LayoutInflater) context
|
||||
.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
|
||||
vi.inflate(R.layout.group_item, this);
|
||||
// title = (TextView) findViewById(R.id.title);
|
||||
volumeSeekBar = (SeekBar) findViewById(R.id.volumeSeekBar);
|
||||
ibMute = (ImageButton) findViewById(R.id.ibMute);
|
||||
ibMute.setImageResource(R.drawable.ic_speaker_icon);
|
||||
ibMute.setOnClickListener(this);
|
||||
ibSettings = (ImageButton) findViewById(R.id.ibSettings);
|
||||
ibSettings.setOnClickListener(this);
|
||||
llVolume = (LinearLayout) findViewById(R.id.llVolume);
|
||||
llVolume.setVisibility(GONE);
|
||||
llClient = (LinearLayout) findViewById(R.id.llClient);
|
||||
llClient.setLayoutParams(new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT));
|
||||
tvStreamName = (TextView) findViewById(R.id.tvStreamName);
|
||||
volumeSeekBar.setOnSeekBarChangeListener(this);
|
||||
volumeSeekBar.setOnTouchListener(this);
|
||||
this.server = server;
|
||||
clientItems = new Vector<>();
|
||||
clientVolumes = new Vector<>();
|
||||
setGroup(group);
|
||||
}
|
||||
|
||||
private void update() {
|
||||
// title.setText(group.getName());
|
||||
llClient.removeAllViews();
|
||||
clientItems.clear();
|
||||
for (Client client : group.getClients()) {
|
||||
if ((client == null) || client.isDeleted() || (hideOffline && !client.isConnected()))
|
||||
continue;
|
||||
|
||||
ClientItem clientItem = new ClientItem(this.getContext(), client);
|
||||
clientItem.setListener(this);
|
||||
clientItems.add(clientItem);
|
||||
llClient.addView(clientItem);
|
||||
}
|
||||
|
||||
if (group.isMuted())
|
||||
ibMute.setImageResource(R.drawable.ic_mute_icon);
|
||||
else
|
||||
ibMute.setImageResource(R.drawable.ic_speaker_icon);
|
||||
|
||||
if ((clientItems.size() >= 2) || ((clientItems.size() == 1) && group.isMuted()))
|
||||
llVolume.setVisibility(VISIBLE);
|
||||
else
|
||||
llVolume.setVisibility(GONE);
|
||||
updateVolume();
|
||||
|
||||
Stream stream = server.getStream(group.getStreamId());
|
||||
if ((tvStreamName == null) || (stream == null))
|
||||
return;
|
||||
tvStreamName.setText(stream.getName());
|
||||
/* String codec = stream.getUri().getQuery().get("codec");
|
||||
if (codec.contains(":"))
|
||||
codec = codec.split(":")[0];
|
||||
tvStreamState.setText(stream.getUri().getQuery().get("sampleformat") + " - " + codec + " - " + stream.getStatus().toString());
|
||||
|
||||
title.setEnabled(group.isConnected());
|
||||
volumeSeekBar.setProgress(group.getConfig().getVolume().getPercent());
|
||||
if (client.getConfig().getVolume().isMuted())
|
||||
ibMute.setImageResource(R.drawable.ic_mute_icon);
|
||||
else
|
||||
ibMute.setImageResource(R.drawable.ic_speaker_icon);
|
||||
*/
|
||||
}
|
||||
|
||||
private void updateVolume() {
|
||||
double meanVolume = 0;
|
||||
for (ClientItem c : clientItems) {
|
||||
meanVolume += c.getClient().getConfig().getVolume().getPercent();
|
||||
}
|
||||
meanVolume /= clientItems.size();
|
||||
volumeSeekBar.setProgress((int) (Math.ceil(meanVolume)));
|
||||
}
|
||||
|
||||
public Group getGroup() {
|
||||
return group;
|
||||
}
|
||||
|
||||
public void setGroup(final Group group) {
|
||||
this.group = group;
|
||||
update();
|
||||
}
|
||||
|
||||
public void setListener(GroupItemListener listener) {
|
||||
this.listener = listener;
|
||||
}
|
||||
|
||||
public void setHideOffline(boolean hideOffline) {
|
||||
if (this.hideOffline == hideOffline)
|
||||
return;
|
||||
this.hideOffline = hideOffline;
|
||||
update();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
|
||||
if (!fromUser)
|
||||
return;
|
||||
|
||||
int delta = progress - groupVolume;
|
||||
if (delta == 0)
|
||||
return;
|
||||
|
||||
double ratio;
|
||||
if (delta < 0)
|
||||
ratio = (double) (groupVolume - progress) / (double) groupVolume;
|
||||
else
|
||||
ratio = (double) (progress - groupVolume) / (double) (100 - groupVolume);
|
||||
|
||||
for (int i = 0; i < clientItems.size(); ++i) {
|
||||
ClientItem clientItem = clientItems.get(i);
|
||||
int clientVolume = clientVolumes.get(i);
|
||||
int newVolume = clientVolume;
|
||||
if (delta < 0)
|
||||
newVolume -= ratio * clientVolume;
|
||||
else
|
||||
newVolume += ratio * (100 - clientVolume);
|
||||
Volume volume = clientItem.getClient().getConfig().getVolume();
|
||||
volume.setPercent(newVolume);
|
||||
clientItem.update();
|
||||
}
|
||||
if (listener != null)
|
||||
listener.onGroupVolumeChanged(this);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public boolean onTouch(View v, MotionEvent event) {
|
||||
if (event.getAction() == MotionEvent.ACTION_DOWN) {
|
||||
clientVolumes.clear();
|
||||
for (int i = 0; i < clientItems.size(); ++i)
|
||||
clientVolumes.add(clientItems.get(i).getClient().getConfig().getVolume().getPercent());
|
||||
groupVolume = volumeSeekBar.getProgress();
|
||||
Log.d(TAG, "onTouch: " + groupVolume);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
if (v == ibMute) {
|
||||
group.setMuted(!group.isMuted());
|
||||
update();
|
||||
listener.onMute(this, group.isMuted());
|
||||
} else if (v == ibSettings) {
|
||||
listener.onPropertiesClicked(this);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onStartTrackingTouch(SeekBar seekBar) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onStopTrackingTouch(SeekBar seekBar) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onVolumeChanged(ClientItem clientItem, int percent, boolean mute) {
|
||||
if (listener != null)
|
||||
listener.onVolumeChanged(this, clientItem, percent, mute);
|
||||
updateVolume();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDeleteClicked(ClientItem clientItem) {
|
||||
if (listener != null)
|
||||
listener.onDeleteClicked(this, clientItem);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onPropertiesClicked(ClientItem clientItem) {
|
||||
if (listener != null)
|
||||
listener.onClientPropertiesClicked(this, clientItem);
|
||||
}
|
||||
|
||||
|
||||
public interface GroupItemListener {
|
||||
void onGroupVolumeChanged(GroupItem group);
|
||||
|
||||
void onMute(GroupItem group, boolean mute);
|
||||
|
||||
void onVolumeChanged(GroupItem group, ClientItem clientItem, int percent, boolean mute);
|
||||
|
||||
void onDeleteClicked(GroupItem group, ClientItem clientItem);
|
||||
|
||||
void onClientPropertiesClicked(GroupItem group, ClientItem clientItem);
|
||||
|
||||
void onPropertiesClicked(GroupItem group);
|
||||
}
|
||||
|
||||
}
|
|
@ -1,192 +0,0 @@
|
|||
/*
|
||||
* This file is part of snapcast
|
||||
* Copyright (C) 2014-2017 Johannes Pohl
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package de.badaix.snapcast;
|
||||
|
||||
import android.content.Context;
|
||||
import android.os.Bundle;
|
||||
import android.support.annotation.NonNull;
|
||||
import android.support.annotation.Nullable;
|
||||
import android.support.v4.app.Fragment;
|
||||
import android.util.Log;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.ArrayAdapter;
|
||||
import android.widget.ListView;
|
||||
|
||||
import de.badaix.snapcast.control.json.Client;
|
||||
import de.badaix.snapcast.control.json.Group;
|
||||
import de.badaix.snapcast.control.json.ServerStatus;
|
||||
|
||||
|
||||
/**
|
||||
* A simple {@link Fragment} subclass.
|
||||
* Activities that contain this fragment must implement the
|
||||
* {@link GroupItem.GroupItemListener} interface
|
||||
* to handle interaction events.
|
||||
*/
|
||||
public class GroupListFragment extends Fragment {
|
||||
|
||||
private static final String TAG = "GroupList";
|
||||
|
||||
private GroupItem.GroupItemListener groupItemListener;
|
||||
private GroupAdapter groupAdapter;
|
||||
private ServerStatus serverStatus = null;
|
||||
private boolean hideOffline = false;
|
||||
|
||||
public GroupListFragment() {
|
||||
// Required empty public constructor
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
// if (getArguments() != null) {
|
||||
// mParam1 = getArguments().getString(ARG_PARAM1);
|
||||
// }
|
||||
}
|
||||
|
||||
@Override
|
||||
public View onCreateView(LayoutInflater inflater, ViewGroup container,
|
||||
Bundle savedInstanceState) {
|
||||
// Inflate the layout for this fragment
|
||||
Log.d(TAG, "onCreateView: " + this.toString());
|
||||
View view = inflater.inflate(R.layout.fragment_group_list, container, false);
|
||||
ListView lvGroup = (ListView) view.findViewById(R.id.lvGroup);
|
||||
groupAdapter = new GroupAdapter(getContext(), groupItemListener);
|
||||
groupAdapter.setHideOffline(hideOffline);
|
||||
groupAdapter.updateServer(serverStatus);
|
||||
lvGroup.setAdapter(groupAdapter);
|
||||
updateGui();
|
||||
return view;
|
||||
}
|
||||
|
||||
|
||||
private void updateGui() {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onAttach(Context context) {
|
||||
super.onAttach(context);
|
||||
if (context instanceof GroupItem.GroupItemListener) {
|
||||
groupItemListener = (GroupItem.GroupItemListener) context;
|
||||
} else {
|
||||
throw new RuntimeException(context.toString()
|
||||
+ " must implement GroupItemListener");
|
||||
}
|
||||
updateGui();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDetach() {
|
||||
super.onDetach();
|
||||
groupItemListener = null;
|
||||
}
|
||||
|
||||
public void updateServer(final ServerStatus serverStatus) {
|
||||
this.serverStatus = serverStatus;
|
||||
if (groupAdapter != null)
|
||||
groupAdapter.updateServer(serverStatus);
|
||||
}
|
||||
|
||||
public void setHideOffline(boolean hide) {
|
||||
this.hideOffline = hide;
|
||||
if (groupAdapter != null)
|
||||
groupAdapter.setHideOffline(hideOffline);
|
||||
}
|
||||
|
||||
public class GroupAdapter extends ArrayAdapter<Group> {
|
||||
private Context context;
|
||||
private GroupItem.GroupItemListener listener;
|
||||
private boolean hideOffline = false;
|
||||
private ServerStatus serverStatus = new ServerStatus();
|
||||
|
||||
GroupAdapter(Context context, GroupItem.GroupItemListener listener) {
|
||||
super(context, 0);
|
||||
this.context = context;
|
||||
this.listener = listener;
|
||||
}
|
||||
|
||||
@Override
|
||||
public
|
||||
@NonNull
|
||||
View getView(int position, @Nullable View convertView,
|
||||
@NonNull ViewGroup parent) {
|
||||
Group group = getItem(position);
|
||||
final GroupItem groupItem;
|
||||
|
||||
if (convertView != null) {
|
||||
groupItem = (GroupItem) convertView;
|
||||
groupItem.setGroup(group);
|
||||
} else {
|
||||
groupItem = new GroupItem(context, serverStatus, group);
|
||||
}
|
||||
groupItem.setHideOffline(hideOffline);
|
||||
groupItem.setListener(listener);
|
||||
return groupItem;
|
||||
}
|
||||
|
||||
void updateServer(final ServerStatus serverStatus) {
|
||||
if (serverStatus != null) {
|
||||
GroupAdapter.this.serverStatus = serverStatus;
|
||||
update();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void update() {
|
||||
getActivity().runOnUiThread(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
clear();
|
||||
for (Group group : GroupAdapter.this.serverStatus.getGroups()) {
|
||||
if (group.getClients().isEmpty())
|
||||
continue;
|
||||
|
||||
int onlineCount = 0;
|
||||
int count = 0;
|
||||
for (Client client : group.getClients()) {
|
||||
if (client == null || client.isDeleted())
|
||||
continue;
|
||||
if (client.isConnected())// && client.getConfig().getStream().equals(GroupListFragment.this.stream.getId()))
|
||||
onlineCount++;
|
||||
count++;
|
||||
}
|
||||
|
||||
if ((onlineCount > 0) || (!hideOffline && (count > 0)))
|
||||
add(group);
|
||||
}
|
||||
|
||||
if (getActivity() != null)
|
||||
notifyDataSetChanged();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
void setHideOffline(boolean hideOffline) {
|
||||
if (this.hideOffline == hideOffline)
|
||||
return;
|
||||
this.hideOffline = hideOffline;
|
||||
update();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
|
@ -1,67 +0,0 @@
|
|||
/*
|
||||
* This file is part of snapcast
|
||||
* Copyright (C) 2014-2017 Johannes Pohl
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package de.badaix.snapcast;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.content.Intent;
|
||||
import android.os.Bundle;
|
||||
import android.support.v7.app.AppCompatActivity;
|
||||
import android.view.MenuItem;
|
||||
|
||||
/**
|
||||
* Created by johannes on 06.12.16.
|
||||
*/
|
||||
|
||||
public class GroupSettingsActivity extends AppCompatActivity {
|
||||
|
||||
private GroupSettingsFragment groupSettingsFragment;
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
|
||||
groupSettingsFragment = new GroupSettingsFragment();
|
||||
groupSettingsFragment.setArguments(getIntent().getExtras());
|
||||
// Display the fragment as the main content.
|
||||
getFragmentManager().beginTransaction()
|
||||
.replace(android.R.id.content, groupSettingsFragment).commit();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onOptionsItemSelected(MenuItem item) {
|
||||
if (item.getItemId() == android.R.id.home) {
|
||||
onBackPressed();
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onBackPressed() {
|
||||
Intent intent = new Intent();
|
||||
intent.putExtra("group", groupSettingsFragment.getGroup().getId());
|
||||
if (groupSettingsFragment.didStreamChange())
|
||||
intent.putExtra("stream", groupSettingsFragment.getStream());
|
||||
if (groupSettingsFragment.didClientsChange())
|
||||
intent.putStringArrayListExtra("clients", groupSettingsFragment.getClients());
|
||||
setResult(Activity.RESULT_OK, intent);
|
||||
finish();
|
||||
}
|
||||
}
|
||||
|
|
@ -1,162 +0,0 @@
|
|||
/*
|
||||
* This file is part of snapcast
|
||||
* Copyright (C) 2014-2017 Johannes Pohl
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package de.badaix.snapcast;
|
||||
|
||||
import android.os.Bundle;
|
||||
import android.preference.CheckBoxPreference;
|
||||
import android.preference.ListPreference;
|
||||
import android.preference.Preference;
|
||||
import android.preference.PreferenceCategory;
|
||||
import android.preference.PreferenceFragment;
|
||||
import android.preference.PreferenceScreen;
|
||||
|
||||
import org.json.JSONException;
|
||||
import org.json.JSONObject;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.Comparator;
|
||||
|
||||
import de.badaix.snapcast.control.json.Client;
|
||||
import de.badaix.snapcast.control.json.Group;
|
||||
import de.badaix.snapcast.control.json.ServerStatus;
|
||||
import de.badaix.snapcast.control.json.Stream;
|
||||
|
||||
/**
|
||||
* Created by johannes on 06.12.16.
|
||||
*/
|
||||
|
||||
public class GroupSettingsFragment extends PreferenceFragment {
|
||||
|
||||
//private static final String TAG = "GroupSettingsFragment";
|
||||
|
||||
private ListPreference prefStreams;
|
||||
private Group group = null;
|
||||
private ServerStatus serverStatus = null;
|
||||
private PreferenceCategory prefCatClients = null;
|
||||
|
||||
private String oldClients = "";
|
||||
private String oldStream = "";
|
||||
|
||||
@Override
|
||||
public void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
|
||||
// Load the preferences from an XML resource
|
||||
addPreferencesFromResource(R.xml.group_preferences);
|
||||
PreferenceScreen screen = this.getPreferenceScreen();
|
||||
|
||||
prefStreams = (ListPreference) findPreference("pref_stream");
|
||||
|
||||
Bundle bundle = getArguments();
|
||||
try {
|
||||
group = new Group(new JSONObject(bundle.getString("group")));
|
||||
serverStatus = new ServerStatus(new JSONObject(bundle.getString("serverStatus")));
|
||||
} catch (JSONException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
final ArrayList<Stream> streams = serverStatus.getStreams();
|
||||
final CharSequence[] streamNames = new CharSequence[streams.size()];
|
||||
final CharSequence[] streamIds = new CharSequence[streams.size()];
|
||||
for (int i = 0; i < streams.size(); ++i) {
|
||||
streamNames[i] = streams.get(i).getName();
|
||||
streamIds[i] = streams.get(i).getId();
|
||||
}
|
||||
|
||||
prefStreams.setEntries(streamNames);
|
||||
prefStreams.setEntryValues(streamIds);
|
||||
|
||||
for (int i = 0; i < streams.size(); ++i) {
|
||||
if (streamIds[i].equals(group.getStreamId())) {
|
||||
prefStreams.setTitle(streamNames[i]);
|
||||
prefStreams.setValueIndex(i);
|
||||
oldStream = prefStreams.getValue();
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
prefStreams.setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() {
|
||||
@Override
|
||||
public boolean onPreferenceChange(Preference preference, Object newValue) {
|
||||
for (int i = 0; i < streams.size(); ++i) {
|
||||
if (streamIds[i].equals(newValue)) {
|
||||
prefStreams.setTitle(streamNames[i]);
|
||||
// client.getConfig().setStream(streamIds[i].toString());
|
||||
prefStreams.setValueIndex(i);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
prefCatClients = (PreferenceCategory) findPreference("pref_cat_clients");
|
||||
ArrayList<CheckBoxPreference> allClients = new ArrayList<>();
|
||||
for (Group g : serverStatus.getGroups()) {
|
||||
for (Client client : g.getClients()) {
|
||||
CheckBoxPreference checkBoxPref = new CheckBoxPreference(screen.getContext());
|
||||
checkBoxPref.setKey(client.getId());
|
||||
checkBoxPref.setTitle(client.getVisibleName());
|
||||
checkBoxPref.setChecked(g.getId().equals(group.getId()));
|
||||
checkBoxPref.setPersistent(false);
|
||||
allClients.add(checkBoxPref);
|
||||
}
|
||||
}
|
||||
Collections.sort(allClients, new Comparator<CheckBoxPreference>() {
|
||||
@Override
|
||||
public int compare(CheckBoxPreference lhs, CheckBoxPreference rhs) {
|
||||
return lhs.getTitle().toString().compareToIgnoreCase(rhs.getTitle().toString());
|
||||
}
|
||||
});
|
||||
for (CheckBoxPreference pref : allClients)
|
||||
prefCatClients.addPreference(pref);
|
||||
|
||||
oldClients = getClients().toString();
|
||||
}
|
||||
|
||||
public ArrayList<String> getClients() {
|
||||
ArrayList<String> clients = new ArrayList<>();
|
||||
for (int i = 0; i < prefCatClients.getPreferenceCount(); ++i) {
|
||||
CheckBoxPreference checkBoxPref = (CheckBoxPreference) prefCatClients.getPreference(i);
|
||||
if (checkBoxPref.isChecked())
|
||||
clients.add(checkBoxPref.getKey());
|
||||
}
|
||||
return clients;
|
||||
}
|
||||
|
||||
|
||||
public boolean didStreamChange() {
|
||||
return !oldStream.equals(prefStreams.getValue());
|
||||
}
|
||||
|
||||
public boolean didClientsChange() {
|
||||
return !oldClients.equalsIgnoreCase(getClients().toString());
|
||||
}
|
||||
|
||||
public String getStream() {
|
||||
return prefStreams.getValue();
|
||||
}
|
||||
|
||||
public Group getGroup() {
|
||||
return group;
|
||||
}
|
||||
}
|
|
@ -1,738 +0,0 @@
|
|||
/*
|
||||
* This file is part of snapcast
|
||||
* Copyright (C) 2014-2017 Johannes Pohl
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package de.badaix.snapcast;
|
||||
|
||||
import android.content.ComponentName;
|
||||
import android.content.Context;
|
||||
import android.content.DialogInterface;
|
||||
import android.content.Intent;
|
||||
import android.content.ServiceConnection;
|
||||
import android.content.pm.PackageInfo;
|
||||
import android.content.pm.PackageManager;
|
||||
import android.media.AudioFormat;
|
||||
import android.media.AudioManager;
|
||||
import android.media.AudioRecord;
|
||||
import android.net.nsd.NsdServiceInfo;
|
||||
import android.os.Build;
|
||||
import android.os.Bundle;
|
||||
import android.os.IBinder;
|
||||
import android.support.design.widget.CoordinatorLayout;
|
||||
import android.support.design.widget.Snackbar;
|
||||
import android.support.v7.app.ActionBar;
|
||||
import android.support.v7.app.AlertDialog;
|
||||
import android.support.v7.app.AppCompatActivity;
|
||||
import android.support.v7.widget.Toolbar;
|
||||
import android.text.TextUtils;
|
||||
import android.util.Log;
|
||||
import android.view.Menu;
|
||||
import android.view.MenuItem;
|
||||
import android.view.View;
|
||||
import android.view.WindowManager;
|
||||
import android.widget.Button;
|
||||
|
||||
import org.json.JSONException;
|
||||
import org.json.JSONObject;
|
||||
|
||||
import java.net.UnknownHostException;
|
||||
import java.util.ArrayList;
|
||||
|
||||
import de.badaix.snapcast.control.RemoteControl;
|
||||
import de.badaix.snapcast.control.json.Client;
|
||||
import de.badaix.snapcast.control.json.Group;
|
||||
import de.badaix.snapcast.control.json.ServerStatus;
|
||||
import de.badaix.snapcast.control.json.Stream;
|
||||
import de.badaix.snapcast.control.json.Volume;
|
||||
import de.badaix.snapcast.utils.NsdHelper;
|
||||
import de.badaix.snapcast.utils.Settings;
|
||||
import de.badaix.snapcast.utils.Setup;
|
||||
|
||||
public class MainActivity extends AppCompatActivity implements GroupItem.GroupItemListener, RemoteControl.RemoteControlListener, SnapclientService.SnapclientListener, NsdHelper.NsdHelperListener {
|
||||
|
||||
static final int CLIENT_PROPERTIES_REQUEST = 1;
|
||||
static final int GROUP_PROPERTIES_REQUEST = 2;
|
||||
private static final String TAG = "Main";
|
||||
private static final String SERVICE_NAME = "Snapcast";// #2";
|
||||
boolean bound = false;
|
||||
private MenuItem miStartStop = null;
|
||||
private MenuItem miSettings = null;
|
||||
// private MenuItem miRefresh = null;
|
||||
private String host = "";
|
||||
private int port = 1704;
|
||||
private int controlPort = 1705;
|
||||
private RemoteControl remoteControl = null;
|
||||
private ServerStatus serverStatus = null;
|
||||
private SnapclientService snapclientService;
|
||||
private GroupListFragment groupListFragment;
|
||||
private Snackbar warningSamplerateSnackbar = null;
|
||||
private int nativeSampleRate = 0;
|
||||
private CoordinatorLayout coordinatorLayout;
|
||||
private Button btnConnect = null;
|
||||
private boolean batchActive = false;
|
||||
|
||||
|
||||
/**
|
||||
* Defines callbacks for service binding, passed to bindService()
|
||||
*/
|
||||
private ServiceConnection mConnection = new ServiceConnection() {
|
||||
|
||||
@Override
|
||||
public void onServiceConnected(ComponentName className,
|
||||
IBinder service) {
|
||||
// We've bound to LocalService, cast the IBinder and get LocalService instance
|
||||
SnapclientService.LocalBinder binder = (SnapclientService.LocalBinder) service;
|
||||
snapclientService = binder.getService();
|
||||
snapclientService.setListener(MainActivity.this);
|
||||
bound = true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onServiceDisconnected(ComponentName arg0) {
|
||||
bound = false;
|
||||
}
|
||||
};
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
setContentView(R.layout.activity_main);
|
||||
|
||||
for (int rate : new int[]{8000, 11025, 16000, 22050, 44100, 48000}) { // add the rates you wish to check against
|
||||
Log.d(TAG, "Samplerate: " + rate);
|
||||
int bufferSize = AudioRecord.getMinBufferSize(rate, AudioFormat.CHANNEL_OUT_STEREO, AudioFormat.ENCODING_PCM_16BIT);
|
||||
if (bufferSize > 0) {
|
||||
Log.d(TAG, "Samplerate: " + rate + ", buffer: " + bufferSize);
|
||||
}
|
||||
}
|
||||
|
||||
AudioManager audioManager = (AudioManager) this.getSystemService(Context.AUDIO_SERVICE);
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1) {
|
||||
String rate = audioManager.getProperty(AudioManager.PROPERTY_OUTPUT_SAMPLE_RATE);
|
||||
nativeSampleRate = Integer.valueOf(rate);
|
||||
// String size = audioManager.getProperty(AudioManager.PROPERTY_OUTPUT_FRAMES_PER_BUFFER);
|
||||
// tvInfo.setText("Sample rate: " + rate + ", buffer size: " + size);
|
||||
}
|
||||
|
||||
coordinatorLayout = (CoordinatorLayout) findViewById(R.id.myCoordinatorLayout);
|
||||
Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
|
||||
setSupportActionBar(toolbar);
|
||||
|
||||
btnConnect = (Button) findViewById(R.id.btnConnect);
|
||||
btnConnect.setVisibility(View.GONE);
|
||||
// Create the adapter that will return a fragment for each of the three
|
||||
// primary sections of the activity.
|
||||
|
||||
groupListFragment = (GroupListFragment) getSupportFragmentManager().findFragmentById(R.id.groupListFragment);
|
||||
groupListFragment.setHideOffline(Settings.getInstance(this).getBoolean("hide_offline", false));
|
||||
|
||||
setActionbarSubtitle("Host: no Snapserver found");
|
||||
|
||||
new Thread(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
Log.d(TAG, "copying snapclient");
|
||||
Setup.copyBinAsset(MainActivity.this, "snapclient", "snapclient");
|
||||
Log.d(TAG, "done copying snapclient");
|
||||
}
|
||||
}).start();
|
||||
|
||||
}
|
||||
|
||||
public void checkFirstRun() {
|
||||
PackageInfo pInfo;
|
||||
try {
|
||||
pInfo = getPackageManager().getPackageInfo(getPackageName(), 0);
|
||||
final int verCode = pInfo.versionCode;
|
||||
int lastRunVersion = Settings.getInstance(this).getInt("lastRunVersion", 0);
|
||||
Log.d(TAG, "lastRunVersion: " + lastRunVersion + ", version: " + verCode);
|
||||
if (lastRunVersion < verCode) {
|
||||
// Place your dialog code here to display the dialog
|
||||
new AlertDialog.Builder(this).setTitle(R.string.first_run_title).setMessage(R.string.first_run_text).setPositiveButton(android.R.string.ok, new DialogInterface.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(DialogInterface dialog, int which) {
|
||||
Settings.getInstance(MainActivity.this).put("lastRunVersion", verCode);
|
||||
}
|
||||
}).setCancelable(true).show();
|
||||
}
|
||||
} catch (PackageManager.NameNotFoundException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onCreateOptionsMenu(Menu menu) {
|
||||
// Inflate the menu; this adds items to the action bar if it is present.
|
||||
getMenuInflater().inflate(R.menu.menu_snapcast, menu);
|
||||
miStartStop = menu.findItem(R.id.action_play_stop);
|
||||
miSettings = menu.findItem(R.id.action_settings);
|
||||
// miRefresh = menu.findItem(R.id.action_refresh);
|
||||
updateStartStopMenuItem();
|
||||
boolean isChecked = Settings.getInstance(this).getBoolean("hide_offline", false);
|
||||
MenuItem menuItem = menu.findItem(R.id.action_hide_offline);
|
||||
menuItem.setChecked(isChecked);
|
||||
// setHost(host, port, controlPort);
|
||||
if (remoteControl != null) {
|
||||
updateMenuItems(remoteControl.isConnected());
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onOptionsItemSelected(MenuItem item) {
|
||||
// Handle action bar item clicks here. The action bar will
|
||||
// automatically handle clicks on the Home/Up button, so long
|
||||
// as you specify a parent activity in AndroidManifest.xml.
|
||||
int id = item.getItemId();
|
||||
|
||||
//noinspection SimplifiableIfStatement
|
||||
if (id == R.id.action_settings) {
|
||||
ServerDialogFragment serverDialogFragment = new ServerDialogFragment();
|
||||
serverDialogFragment.setHost(Settings.getInstance(this).getHost(), Settings.getInstance(this).getStreamPort(), Settings.getInstance(this).getControlPort());
|
||||
serverDialogFragment.setAutoStart(Settings.getInstance(this).isAutostart());
|
||||
serverDialogFragment.setListener(new ServerDialogFragment.ServerDialogListener() {
|
||||
@Override
|
||||
public void onHostChanged(String host, int streamPort, int controlPort) {
|
||||
setHost(host, streamPort, controlPort);
|
||||
startRemoteControl();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onAutoStartChanged(boolean autoStart) {
|
||||
Settings.getInstance(MainActivity.this).setAutostart(autoStart);
|
||||
}
|
||||
});
|
||||
serverDialogFragment.show(getSupportFragmentManager(), "serverDialogFragment");
|
||||
// NsdHelper.getInstance(this).startListening("_snapcast._tcp.", SERVICE_NAME, this);
|
||||
return true;
|
||||
} else if (id == R.id.action_play_stop) {
|
||||
if (bound && snapclientService.isRunning()) {
|
||||
stopSnapclient();
|
||||
} else {
|
||||
item.setEnabled(false);
|
||||
startSnapclient();
|
||||
}
|
||||
return true;
|
||||
} else if (id == R.id.action_hide_offline) {
|
||||
item.setChecked(!item.isChecked());
|
||||
Settings.getInstance(this).put("hide_offline", item.isChecked());
|
||||
groupListFragment.setHideOffline(item.isChecked());
|
||||
return true;
|
||||
} else if (id == R.id.action_refresh) {
|
||||
startRemoteControl();
|
||||
remoteControl.getServerStatus();
|
||||
} else if (id == R.id.action_about) {
|
||||
Intent intent = new Intent(this, AboutActivity.class);
|
||||
startActivity(intent);
|
||||
}
|
||||
|
||||
return super.onOptionsItemSelected(item);
|
||||
}
|
||||
|
||||
private void updateStartStopMenuItem() {
|
||||
MainActivity.this.runOnUiThread(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
|
||||
if (bound && snapclientService.isRunning()) {
|
||||
Log.d(TAG, "updateStartStopMenuItem: ic_media_stop");
|
||||
miStartStop.setIcon(R.drawable.ic_media_stop);
|
||||
} else {
|
||||
Log.d(TAG, "updateStartStopMenuItem: ic_media_play");
|
||||
miStartStop.setIcon(R.drawable.ic_media_play);
|
||||
}
|
||||
if (miStartStop != null) {
|
||||
miStartStop.setEnabled(true);
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private void startSnapclient() {
|
||||
if (TextUtils.isEmpty(host))
|
||||
return;
|
||||
|
||||
Intent i = new Intent(this, SnapclientService.class);
|
||||
i.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_SINGLE_TOP);
|
||||
i.putExtra(SnapclientService.EXTRA_HOST, host);
|
||||
i.putExtra(SnapclientService.EXTRA_PORT, port);
|
||||
i.setAction(SnapclientService.ACTION_START);
|
||||
|
||||
startService(i);
|
||||
}
|
||||
|
||||
private void stopSnapclient() {
|
||||
if (bound)
|
||||
snapclientService.stopPlayer();
|
||||
// stopService(new Intent(this, SnapclientService.class));
|
||||
getWindow().clearFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
|
||||
}
|
||||
|
||||
|
||||
private void startRemoteControl() {
|
||||
if (remoteControl == null)
|
||||
remoteControl = new RemoteControl(this);
|
||||
if (!host.isEmpty())
|
||||
remoteControl.connect(host, controlPort);
|
||||
}
|
||||
|
||||
private void stopRemoteControl() {
|
||||
if ((remoteControl != null) && (remoteControl.isConnected()))
|
||||
remoteControl.disconnect();
|
||||
remoteControl = null;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void onResume() {
|
||||
super.onResume();
|
||||
startRemoteControl();
|
||||
checkFirstRun();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onStart() {
|
||||
super.onStart();
|
||||
|
||||
if (TextUtils.isEmpty(Settings.getInstance(this).getHost()))
|
||||
NsdHelper.getInstance(this).startListening("_snapcast._tcp.", SERVICE_NAME, this);
|
||||
else
|
||||
setHost(Settings.getInstance(this).getHost(), Settings.getInstance(this).getStreamPort(), Settings.getInstance(this).getControlPort());
|
||||
|
||||
Intent intent = new Intent(this, SnapclientService.class);
|
||||
bindService(intent, mConnection, Context.BIND_AUTO_CREATE);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDestroy() {
|
||||
stopRemoteControl();
|
||||
super.onDestroy();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onStop() {
|
||||
super.onStop();
|
||||
|
||||
NsdHelper.getInstance(this).stopListening();
|
||||
// Unbind from the service
|
||||
if (bound) {
|
||||
unbindService(mConnection);
|
||||
bound = false;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onPlayerStart(SnapclientService snapclientService) {
|
||||
Log.d(TAG, "onPlayerStart");
|
||||
updateStartStopMenuItem();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onPlayerStop(SnapclientService snapclientService) {
|
||||
Log.d(TAG, "onPlayerStop");
|
||||
updateStartStopMenuItem();
|
||||
if (warningSamplerateSnackbar != null)
|
||||
warningSamplerateSnackbar.dismiss();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onLog(SnapclientService snapclientService, String timestamp, String logClass, String msg) {
|
||||
Log.d(TAG, "[" + logClass + "] " + msg);
|
||||
if ("Notice".equals(logClass)) {
|
||||
if (msg.startsWith("sampleformat")) {
|
||||
msg = msg.substring(msg.indexOf(":") + 2);
|
||||
Log.d(TAG, "sampleformat: " + msg);
|
||||
if (msg.indexOf(':') > 0) {
|
||||
int samplerate = Integer.valueOf(msg.substring(0, msg.indexOf(':')));
|
||||
|
||||
if (warningSamplerateSnackbar != null)
|
||||
warningSamplerateSnackbar.dismiss();
|
||||
|
||||
if ((nativeSampleRate != 0) && (nativeSampleRate != samplerate)) {
|
||||
warningSamplerateSnackbar = Snackbar.make(coordinatorLayout,
|
||||
getString(R.string.wrong_sample_rate, samplerate, nativeSampleRate), Snackbar.LENGTH_INDEFINITE);
|
||||
warningSamplerateSnackbar.show();
|
||||
} else if (nativeSampleRate == 0) {
|
||||
warningSamplerateSnackbar = Snackbar.make(coordinatorLayout,
|
||||
getString(R.string.unknown_sample_rate), Snackbar.LENGTH_LONG);
|
||||
warningSamplerateSnackbar.show();
|
||||
}
|
||||
}
|
||||
}
|
||||
} else if ("err".equals(logClass) || "Emerg".equals(logClass) || "Alert".equals(logClass) || "Crit".equals(logClass) || "Err".equals(logClass)) {
|
||||
if (warningSamplerateSnackbar != null)
|
||||
warningSamplerateSnackbar.dismiss();
|
||||
warningSamplerateSnackbar = Snackbar.make(findViewById(R.id.myCoordinatorLayout),
|
||||
msg, Snackbar.LENGTH_LONG);
|
||||
warningSamplerateSnackbar.show();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onError(SnapclientService snapclientService, String msg, Exception exception) {
|
||||
updateStartStopMenuItem();
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
|
||||
super.onActivityResult(requestCode, resultCode, data);
|
||||
|
||||
if (resultCode == RESULT_CANCELED) {
|
||||
return;
|
||||
}
|
||||
if (requestCode == CLIENT_PROPERTIES_REQUEST) {
|
||||
Client client;
|
||||
try {
|
||||
client = new Client(new JSONObject(data.getStringExtra("client")));
|
||||
} catch (JSONException e) {
|
||||
e.printStackTrace();
|
||||
return;
|
||||
}
|
||||
|
||||
Client clientOriginal;
|
||||
try {
|
||||
clientOriginal = new Client(new JSONObject(data.getStringExtra("clientOriginal")));
|
||||
} catch (JSONException e) {
|
||||
e.printStackTrace();
|
||||
return;
|
||||
}
|
||||
Log.d(TAG, "new name: " + client.getConfig().getName() + ", old name: " + clientOriginal.getConfig().getName());
|
||||
if (!client.getConfig().getName().equals(clientOriginal.getConfig().getName()))
|
||||
remoteControl.setName(client, client.getConfig().getName());
|
||||
Log.d(TAG, "new latency: " + client.getConfig().getLatency() + ", old latency: " + clientOriginal.getConfig().getLatency());
|
||||
if (client.getConfig().getLatency() != clientOriginal.getConfig().getLatency())
|
||||
remoteControl.setLatency(client, client.getConfig().getLatency());
|
||||
serverStatus.updateClient(client);
|
||||
groupListFragment.updateServer(MainActivity.this.serverStatus);
|
||||
} else if (requestCode == GROUP_PROPERTIES_REQUEST) {
|
||||
String groupId = data.getStringExtra("group");
|
||||
boolean changed = false;
|
||||
if (data.hasExtra("clients")) {
|
||||
ArrayList<String> clients = data.getStringArrayListExtra("clients");
|
||||
remoteControl.setClients(groupId, clients);
|
||||
}
|
||||
if (data.hasExtra("stream")) {
|
||||
String streamId = data.getStringExtra("stream");
|
||||
remoteControl.setStream(groupId, streamId);
|
||||
onStreamChanged(RemoteControl.RPCEvent.response, groupId, streamId);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private void setActionbarSubtitle(final String subtitle) {
|
||||
MainActivity.this.runOnUiThread(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
ActionBar actionBar = getSupportActionBar();
|
||||
if (actionBar != null)
|
||||
actionBar.setSubtitle(subtitle);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private void setHost(final String host, final int streamPort, final int controlPort) {
|
||||
if (TextUtils.isEmpty(host))
|
||||
return;
|
||||
|
||||
this.host = host;
|
||||
this.port = streamPort;
|
||||
this.controlPort = controlPort;
|
||||
Settings.getInstance(this).setHost(host, streamPort, controlPort);
|
||||
}
|
||||
|
||||
public void updateMenuItems(final boolean connected) {
|
||||
this.runOnUiThread(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
if (connected) {
|
||||
if (miSettings != null)
|
||||
miSettings.setShowAsAction(MenuItem.SHOW_AS_ACTION_NEVER);
|
||||
if (miStartStop != null)
|
||||
miStartStop.setVisible(true);
|
||||
// if (miRefresh != null)
|
||||
// miRefresh.setVisible(true);
|
||||
} else {
|
||||
if (miSettings != null)
|
||||
miSettings.setShowAsAction(MenuItem.SHOW_AS_ACTION_ALWAYS);
|
||||
if (miStartStop != null)
|
||||
miStartStop.setVisible(false);
|
||||
// if (miRefresh != null)
|
||||
// miRefresh.setVisible(false);
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void onResolved(NsdHelper nsdHelper, NsdServiceInfo serviceInfo) {
|
||||
Log.d(TAG, "resolved: " + serviceInfo);
|
||||
setHost(serviceInfo.getHost().getCanonicalHostName(), serviceInfo.getPort(), serviceInfo.getPort() + 1);
|
||||
startRemoteControl();
|
||||
NsdHelper.getInstance(this).stopListening();
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void onGroupVolumeChanged(GroupItem groupItem) {
|
||||
remoteControl.setGroupVolume(groupItem.getGroup());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onMute(GroupItem groupItem, boolean mute) {
|
||||
remoteControl.setGroupMuted(groupItem.getGroup(), mute);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onVolumeChanged(GroupItem groupItem, ClientItem clientItem, int percent, boolean mute) {
|
||||
remoteControl.setVolume(clientItem.getClient(), percent, mute);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDeleteClicked(GroupItem groupItem, final ClientItem clientItem) {
|
||||
final Client client = clientItem.getClient();
|
||||
client.setDeleted(true);
|
||||
|
||||
serverStatus.updateClient(client);
|
||||
groupListFragment.updateServer(serverStatus);
|
||||
Snackbar mySnackbar = Snackbar.make(findViewById(R.id.myCoordinatorLayout),
|
||||
getString(R.string.client_deleted, client.getVisibleName()),
|
||||
Snackbar.LENGTH_SHORT);
|
||||
mySnackbar.setAction(R.string.undo_string, new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
client.setDeleted(false);
|
||||
serverStatus.updateClient(client);
|
||||
groupListFragment.updateServer(serverStatus);
|
||||
}
|
||||
});
|
||||
mySnackbar.addCallback(new Snackbar.Callback() {
|
||||
@Override
|
||||
public void onDismissed(Snackbar snackbar, int event) {
|
||||
super.onDismissed(snackbar, event);
|
||||
if (event != DISMISS_EVENT_ACTION) {
|
||||
remoteControl.delete(client);
|
||||
serverStatus.removeClient(client);
|
||||
}
|
||||
}
|
||||
});
|
||||
mySnackbar.show();
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onClientPropertiesClicked(GroupItem groupItem, ClientItem clientItem) {
|
||||
Intent intent = new Intent(this, ClientSettingsActivity.class);
|
||||
intent.putExtra("client", clientItem.getClient().toJson().toString());
|
||||
intent.setFlags(0);
|
||||
startActivityForResult(intent, CLIENT_PROPERTIES_REQUEST);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onPropertiesClicked(GroupItem groupItem) {
|
||||
Intent intent = new Intent(this, GroupSettingsActivity.class);
|
||||
intent.putExtra("serverStatus", serverStatus.toJson().toString());
|
||||
intent.putExtra("group", groupItem.getGroup().toJson().toString());
|
||||
intent.setFlags(0);
|
||||
startActivityForResult(intent, GROUP_PROPERTIES_REQUEST);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onConnected(RemoteControl remoteControl) {
|
||||
setActionbarSubtitle(remoteControl.getHost());
|
||||
remoteControl.getServerStatus();
|
||||
updateMenuItems(true);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onConnecting(RemoteControl remoteControl) {
|
||||
setActionbarSubtitle("connecting: " + remoteControl.getHost());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDisconnected(RemoteControl remoteControl, Exception e) {
|
||||
Log.d(TAG, "onDisconnected");
|
||||
serverStatus = new ServerStatus();
|
||||
groupListFragment.updateServer(serverStatus);
|
||||
if (e != null) {
|
||||
if (e instanceof UnknownHostException)
|
||||
setActionbarSubtitle("error: unknown host");
|
||||
else
|
||||
setActionbarSubtitle("error: " + e.getMessage());
|
||||
} else {
|
||||
setActionbarSubtitle("not connected");
|
||||
}
|
||||
updateMenuItems(false);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void onBatchStart() {
|
||||
batchActive = true;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void onBatchEnd() {
|
||||
batchActive = false;
|
||||
groupListFragment.updateServer(serverStatus);
|
||||
}
|
||||
|
||||
|
||||
|
||||
/*
|
||||
@Override
|
||||
public void onClientEvent(RemoteControl remoteControl, RemoteControl.RpcEvent rpcEvent, Client client, RemoteControl.ClientEvent event) {
|
||||
Log.d(TAG, "onClientEvent: " + event.toString());
|
||||
/// update only in case of notifications
|
||||
if (rpcEvent == RemoteControl.RpcEvent.response)
|
||||
return;
|
||||
|
||||
serverStatus.updateClient(client);
|
||||
groupListFragment.updateServer(serverStatus);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onServerUpdate(RemoteControl remoteControl, RemoteControl.RpcEvent rpcEvent, ServerStatus serverStatus) {
|
||||
this.serverStatus = serverStatus;
|
||||
groupListFragment.updateServer(serverStatus);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onStreamUpdate(RemoteControl remoteControl, RemoteControl.RpcEvent rpcEvent, Stream stream) {
|
||||
serverStatus.updateStream(stream);
|
||||
groupListFragment.updateServer(serverStatus);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onGroupUpdate(RemoteControl remoteControl, RemoteControl.RpcEvent rpcEvent, Group group) {
|
||||
serverStatus.updateGroup(group);
|
||||
groupListFragment.updateServer(serverStatus);
|
||||
}
|
||||
*/
|
||||
|
||||
@Override
|
||||
public void onConnect(Client client) {
|
||||
serverStatus.getClient(client.getId());
|
||||
if (client == null) {
|
||||
remoteControl.getServerStatus();
|
||||
return;
|
||||
}
|
||||
client.setConnected(true);
|
||||
serverStatus.updateClient(client);
|
||||
groupListFragment.updateServer(serverStatus);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDisconnect(String clientId) {
|
||||
Client client = serverStatus.getClient(clientId);
|
||||
if (client == null) {
|
||||
remoteControl.getServerStatus();
|
||||
return;
|
||||
}
|
||||
client.setConnected(false);
|
||||
serverStatus.updateClient(client);
|
||||
groupListFragment.updateServer(serverStatus);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onUpdate(Client client) {
|
||||
serverStatus.updateClient(client);
|
||||
groupListFragment.updateServer(serverStatus);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onVolumeChanged(RemoteControl.RPCEvent event, String clientId, Volume volume) {
|
||||
if (event == RemoteControl.RPCEvent.response)
|
||||
return;
|
||||
Client client = serverStatus.getClient(clientId);
|
||||
if (client == null) {
|
||||
remoteControl.getServerStatus();
|
||||
return;
|
||||
}
|
||||
client.setVolume(volume);
|
||||
if (!batchActive)
|
||||
groupListFragment.updateServer(serverStatus);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onLatencyChanged(RemoteControl.RPCEvent event, String clientId, long latency) {
|
||||
Client client = serverStatus.getClient(clientId);
|
||||
if (client == null) {
|
||||
remoteControl.getServerStatus();
|
||||
return;
|
||||
}
|
||||
client.getConfig().setLatency((int) latency);
|
||||
groupListFragment.updateServer(serverStatus);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onNameChanged(RemoteControl.RPCEvent event, String clientId, String name) {
|
||||
Client client = serverStatus.getClient(clientId);
|
||||
if (client == null) {
|
||||
remoteControl.getServerStatus();
|
||||
return;
|
||||
}
|
||||
client.getConfig().setName(name);
|
||||
groupListFragment.updateServer(serverStatus);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onUpdate(Group group) {
|
||||
serverStatus.updateGroup(group);
|
||||
groupListFragment.updateServer(serverStatus);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onMute(RemoteControl.RPCEvent event, String groupId, boolean mute) {
|
||||
Group g = serverStatus.getGroup(groupId);
|
||||
if (g == null) {
|
||||
remoteControl.getServerStatus();
|
||||
return;
|
||||
}
|
||||
g.setMuted(mute);
|
||||
serverStatus.updateGroup(g);
|
||||
groupListFragment.updateServer(serverStatus);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onStreamChanged(RemoteControl.RPCEvent event, String groupId, String streamId) {
|
||||
Group g = serverStatus.getGroup(groupId);
|
||||
if (g == null) {
|
||||
remoteControl.getServerStatus();
|
||||
return;
|
||||
}
|
||||
g.setStreamId(streamId);
|
||||
serverStatus.updateGroup(g);
|
||||
groupListFragment.updateServer(serverStatus);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onUpdate(ServerStatus server) {
|
||||
this.serverStatus = server;
|
||||
groupListFragment.updateServer(serverStatus);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onUpdate(String streamId, Stream stream) {
|
||||
serverStatus.updateStream(stream);
|
||||
groupListFragment.updateServer(serverStatus);
|
||||
}
|
||||
}
|
||||
|
|
@ -1,164 +0,0 @@
|
|||
/*
|
||||
* This file is part of snapcast
|
||||
* Copyright (C) 2014-2017 Johannes Pohl
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package de.badaix.snapcast;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.app.Dialog;
|
||||
import android.content.Context;
|
||||
import android.content.DialogInterface;
|
||||
import android.net.nsd.NsdServiceInfo;
|
||||
import android.os.Build;
|
||||
import android.os.Bundle;
|
||||
import android.support.v4.app.DialogFragment;
|
||||
import android.support.v7.app.AlertDialog;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.widget.Button;
|
||||
import android.widget.CheckBox;
|
||||
import android.widget.EditText;
|
||||
|
||||
import de.badaix.snapcast.utils.NsdHelper;
|
||||
|
||||
/**
|
||||
* Created by johannes on 21.02.16.
|
||||
*/
|
||||
public class ServerDialogFragment extends DialogFragment implements View.OnClickListener {
|
||||
|
||||
private Button btnScan;
|
||||
private EditText editHost;
|
||||
private EditText editStreamPort;
|
||||
private EditText editControlPort;
|
||||
private CheckBox checkBoxAutoStart;
|
||||
private String host = "";
|
||||
private int streamPort = 1704;
|
||||
private int controlPort = 1705;
|
||||
private boolean autoStart = false;
|
||||
private ServerDialogListener listener = null;
|
||||
|
||||
public void setListener(ServerDialogListener listener) {
|
||||
this.listener = listener;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Dialog onCreateDialog(Bundle savedInstanceState) {
|
||||
AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
|
||||
// Get the layout inflater
|
||||
LayoutInflater inflater = getActivity().getLayoutInflater();
|
||||
// Inflate and set the layout for the dialog
|
||||
// Pass null as the parent view because its going in the dialog layout
|
||||
View view = inflater.inflate(R.layout.dialog_server, null);
|
||||
btnScan = (Button) view.findViewById(R.id.btn_scan);
|
||||
btnScan.setOnClickListener(this);
|
||||
|
||||
editHost = (EditText) view.findViewById(R.id.host);
|
||||
editStreamPort = (EditText) view.findViewById(R.id.stream_port);
|
||||
editControlPort = (EditText) view.findViewById(R.id.control_port);
|
||||
checkBoxAutoStart = (CheckBox) view.findViewById(R.id.checkBoxAutoStart);
|
||||
update();
|
||||
|
||||
builder.setView(view)
|
||||
// Add action buttons
|
||||
.setPositiveButton(android.R.string.ok, new DialogInterface.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(DialogInterface dialog, int id) {
|
||||
// sign in the user ...
|
||||
host = editHost.getText().toString();
|
||||
try {
|
||||
streamPort = Integer.parseInt(editStreamPort.getText().toString());
|
||||
controlPort = Integer.parseInt(editControlPort.getText().toString());
|
||||
} catch (NumberFormatException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
if (listener != null) {
|
||||
listener.onHostChanged(host, streamPort, controlPort);
|
||||
listener.onAutoStartChanged(checkBoxAutoStart.isChecked());
|
||||
}
|
||||
}
|
||||
})
|
||||
.setNegativeButton(android.R.string.cancel, new DialogInterface.OnClickListener() {
|
||||
public void onClick(DialogInterface dialog, int id) {
|
||||
ServerDialogFragment.this.getDialog().cancel();
|
||||
}
|
||||
})
|
||||
.setTitle(R.string.server_host)
|
||||
.setCancelable(false);
|
||||
return builder.create();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
NsdHelper.getInstance(getContext()).startListening("_snapcast._tcp.", "Snapcast", new NsdHelper.NsdHelperListener() {
|
||||
@Override
|
||||
public void onResolved(NsdHelper nsdHelper, NsdServiceInfo serviceInfo) {
|
||||
setHost(serviceInfo.getHost().getCanonicalHostName(), serviceInfo.getPort(), serviceInfo.getPort() + 1);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onAttach(Context context) {
|
||||
super.onAttach(context);
|
||||
|
||||
if (context instanceof Activity) {
|
||||
update();
|
||||
}
|
||||
}
|
||||
|
||||
private void update() {
|
||||
if (this.getActivity() == null)
|
||||
return;
|
||||
|
||||
try {
|
||||
this.getActivity().runOnUiThread(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
try {
|
||||
editHost.setText(host);
|
||||
editStreamPort.setText(Integer.toString(streamPort));
|
||||
editControlPort.setText(Integer.toString(controlPort));
|
||||
checkBoxAutoStart.setChecked(autoStart);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
});
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
public void setHost(String host, int streamPort, int controlPort) {
|
||||
this.host = host;
|
||||
this.streamPort = streamPort;
|
||||
this.controlPort = controlPort;
|
||||
update();
|
||||
}
|
||||
|
||||
public void setAutoStart(boolean autoStart) {
|
||||
this.autoStart = autoStart;
|
||||
update();
|
||||
}
|
||||
|
||||
|
||||
public interface ServerDialogListener {
|
||||
void onHostChanged(String host, int streamPort, int controlPort);
|
||||
|
||||
void onAutoStartChanged(boolean autoStart);
|
||||
}
|
||||
}
|
|
@ -1,258 +0,0 @@
|
|||
/*
|
||||
* This file is part of snapcast
|
||||
* Copyright (C) 2014-2017 Johannes Pohl
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package de.badaix.snapcast;
|
||||
|
||||
import android.app.Notification;
|
||||
import android.app.NotificationManager;
|
||||
import android.app.PendingIntent;
|
||||
import android.app.Service;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.net.wifi.WifiManager;
|
||||
import android.os.Binder;
|
||||
import android.os.IBinder;
|
||||
import android.os.PowerManager;
|
||||
import android.support.v4.app.NotificationCompat;
|
||||
import android.support.v4.app.TaskStackBuilder;
|
||||
|
||||
import java.io.BufferedReader;
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStreamReader;
|
||||
|
||||
import static android.os.PowerManager.PARTIAL_WAKE_LOCK;
|
||||
|
||||
/**
|
||||
* Created by johannes on 01.01.16.
|
||||
*/
|
||||
|
||||
public class SnapclientService extends Service {
|
||||
|
||||
public static final String EXTRA_HOST = "EXTRA_HOST";
|
||||
public static final String EXTRA_PORT = "EXTRA_PORT";
|
||||
public static final String ACTION_START = "ACTION_START";
|
||||
public static final String ACTION_STOP = "ACTION_STOP";
|
||||
private final IBinder mBinder = new LocalBinder();
|
||||
private java.lang.Process process = null;
|
||||
private PowerManager.WakeLock wakeLock = null;
|
||||
private WifiManager.WifiLock wifiWakeLock = null;
|
||||
private Thread reader = null;
|
||||
private boolean running = false;
|
||||
private SnapclientListener listener = null;
|
||||
private boolean logReceived;
|
||||
|
||||
public boolean isRunning() {
|
||||
return running;
|
||||
}
|
||||
|
||||
public void setListener(SnapclientListener listener) {
|
||||
this.listener = listener;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int onStartCommand(Intent intent, int flags, int startId) {
|
||||
if (intent == null)
|
||||
return START_NOT_STICKY;
|
||||
|
||||
if (intent.getAction().equals(ACTION_STOP)) {
|
||||
stopService();
|
||||
return START_NOT_STICKY;
|
||||
} else if (intent.getAction().equals(ACTION_START)) {
|
||||
String host = intent.getStringExtra(EXTRA_HOST);
|
||||
int port = intent.getIntExtra(EXTRA_PORT, 1704);
|
||||
|
||||
Intent stopIntent = new Intent(this, SnapclientService.class);
|
||||
stopIntent.setAction(ACTION_STOP);
|
||||
PendingIntent piStop = PendingIntent.getService(this, 0, stopIntent, 0);
|
||||
|
||||
NotificationCompat.Builder builder =
|
||||
new NotificationCompat.Builder(this)
|
||||
.setSmallIcon(R.drawable.ic_media_play)
|
||||
.setTicker(getText(R.string.ticker_text))
|
||||
.setContentTitle(getText(R.string.notification_title))
|
||||
.setContentText(getText(R.string.notification_text))
|
||||
.setContentInfo(host)
|
||||
.setStyle(new NotificationCompat.BigTextStyle().bigText(getText(R.string.notification_text)))
|
||||
.addAction(R.drawable.ic_media_stop, getString(R.string.stop), piStop);
|
||||
|
||||
Intent resultIntent = new Intent(this, MainActivity.class);
|
||||
|
||||
// The stack builder object will contain an artificial back stack for the
|
||||
// started Activity.
|
||||
// This ensures that navigating backward from the Activity leads out of
|
||||
// your application to the Home screen.
|
||||
TaskStackBuilder stackBuilder = TaskStackBuilder.create(this);
|
||||
// Adds the back stack for the Intent (but not the Intent itself)
|
||||
stackBuilder.addParentStack(MainActivity.class);
|
||||
// Adds the Intent that starts the Activity to the top of the stack
|
||||
stackBuilder.addNextIntent(resultIntent);
|
||||
PendingIntent resultPendingIntent =
|
||||
stackBuilder.getPendingIntent(
|
||||
0,
|
||||
PendingIntent.FLAG_UPDATE_CURRENT
|
||||
);
|
||||
builder.setContentIntent(resultPendingIntent);
|
||||
// mId allows you to update the notification later on.
|
||||
final Notification notification = builder.build();
|
||||
startForeground(123, notification);
|
||||
|
||||
start(host, port);
|
||||
return START_STICKY;
|
||||
}
|
||||
return START_NOT_STICKY;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDestroy() {
|
||||
stop();
|
||||
}
|
||||
|
||||
@Override
|
||||
public IBinder onBind(Intent intent) {
|
||||
return mBinder;
|
||||
}
|
||||
|
||||
public void stopPlayer() {
|
||||
stopService();
|
||||
}
|
||||
|
||||
private void stopService() {
|
||||
stop();
|
||||
stopForeground(true);
|
||||
NotificationManager mNotificationManager =
|
||||
(NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
|
||||
mNotificationManager.cancel(123);
|
||||
}
|
||||
|
||||
private void start(String host, int port) {
|
||||
try {
|
||||
//https://code.google.com/p/android/issues/detail?id=22763
|
||||
if (running)
|
||||
return;
|
||||
File binary = new File(getFilesDir(), "snapclient");
|
||||
android.os.Process.setThreadPriority(android.os.Process.THREAD_PRIORITY_URGENT_AUDIO);
|
||||
|
||||
PowerManager powerManager = (PowerManager) getSystemService(POWER_SERVICE);
|
||||
wakeLock = powerManager.newWakeLock(PARTIAL_WAKE_LOCK, "SnapcastWakeLock");
|
||||
wakeLock.acquire();
|
||||
|
||||
WifiManager wm = (WifiManager) getApplicationContext().getSystemService(WIFI_SERVICE);
|
||||
wifiWakeLock = wm.createWifiLock(WifiManager.WIFI_MODE_FULL_HIGH_PERF, "SnapcastWifiWakeLock");
|
||||
wifiWakeLock.acquire();
|
||||
|
||||
process = new ProcessBuilder()
|
||||
.command(binary.getAbsolutePath(), "-h", host, "-p", Integer.toString(port))
|
||||
.redirectErrorStream(true)
|
||||
.start();
|
||||
|
||||
Thread reader = new Thread(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
BufferedReader bufferedReader = new BufferedReader(
|
||||
new InputStreamReader(process.getInputStream()));
|
||||
String line;
|
||||
try {
|
||||
while ((line = bufferedReader.readLine()) != null) {
|
||||
log(line);
|
||||
}
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
});
|
||||
logReceived = false;
|
||||
reader.start();
|
||||
|
||||
//TODO: wait for started message on stdout
|
||||
/* long now = System.currentTimeMillis();
|
||||
while (!logReceived) {
|
||||
if (System.currentTimeMillis() > now + 1000)
|
||||
throw new Exception("start timeout");
|
||||
Thread.sleep(100, 0);
|
||||
}
|
||||
*/
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
if (listener != null)
|
||||
listener.onError(this, e.getMessage(), e);
|
||||
stop();
|
||||
}
|
||||
}
|
||||
|
||||
private void log(String msg) {
|
||||
if (!logReceived) {
|
||||
logReceived = true;
|
||||
running = true;
|
||||
if (listener != null)
|
||||
listener.onPlayerStart(this);
|
||||
}
|
||||
if (listener != null) {
|
||||
int idxBracketOpen = msg.indexOf('[');
|
||||
int idxBracketClose = msg.indexOf(']', idxBracketOpen);
|
||||
if ((idxBracketOpen > 0) && (idxBracketClose > 0)) {
|
||||
listener.onLog(SnapclientService.this, msg.substring(0, idxBracketOpen - 1), msg.substring(idxBracketOpen + 1, idxBracketClose), msg.substring(idxBracketClose + 2));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void stop() {
|
||||
try {
|
||||
if (reader != null)
|
||||
reader.interrupt();
|
||||
if (process != null)
|
||||
process.destroy();
|
||||
if ((wakeLock != null) && wakeLock.isHeld())
|
||||
wakeLock.release();
|
||||
if ((wifiWakeLock != null) && wifiWakeLock.isHeld())
|
||||
wifiWakeLock.release();
|
||||
android.os.Process.setThreadPriority(android.os.Process.THREAD_PRIORITY_DEFAULT);
|
||||
running = false;
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
if (listener != null)
|
||||
listener.onPlayerStop(this);
|
||||
}
|
||||
|
||||
public interface SnapclientListener {
|
||||
void onPlayerStart(SnapclientService snapclientService);
|
||||
|
||||
void onPlayerStop(SnapclientService snapclientService);
|
||||
|
||||
void onLog(SnapclientService snapclientService, String timestamp, String logClass, String msg);
|
||||
|
||||
void onError(SnapclientService snapclientService, String msg, Exception exception);
|
||||
}
|
||||
|
||||
/**
|
||||
* Class used for the client Binder. Because we know this service always
|
||||
* runs in the same process as its clients, we don't need to deal with IPC.
|
||||
*/
|
||||
public class LocalBinder extends Binder {
|
||||
SnapclientService getService() {
|
||||
// Return this instance of LocalService so clients can call public methods
|
||||
return SnapclientService.this;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
|
@ -1,175 +0,0 @@
|
|||
/*
|
||||
* This file is part of snapcast
|
||||
* Copyright (C) 2014-2017 Johannes Pohl
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package de.badaix.snapcast.control;
|
||||
|
||||
import org.json.JSONException;
|
||||
import org.json.JSONObject;
|
||||
|
||||
/**
|
||||
* Created by johannes on 19.02.17.
|
||||
*/
|
||||
|
||||
class RPCRequest {
|
||||
RPCRequest(JSONObject json) throws JSONException {
|
||||
fromJson(json);
|
||||
}
|
||||
|
||||
RPCRequest(String json) throws JSONException {
|
||||
this(new JSONObject(json));
|
||||
}
|
||||
|
||||
RPCRequest(String method, long id, JSONObject params) {
|
||||
this.method = method;
|
||||
this.id = id;
|
||||
this.params = params;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return toJson().toString();
|
||||
}
|
||||
|
||||
JSONObject toJson() {
|
||||
JSONObject request = new JSONObject();
|
||||
try {
|
||||
request.put("jsonrpc", "2.0");
|
||||
request.put("method", method);
|
||||
request.put("id", id);
|
||||
if (params != null)
|
||||
request.put("params", params);
|
||||
return request;
|
||||
} catch (JSONException e) {
|
||||
e.printStackTrace();
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
void fromJson(JSONObject json) throws JSONException {
|
||||
id = json.getLong("id");
|
||||
method = json.getString("method");
|
||||
if (json.has("params"))
|
||||
params = json.getJSONObject("params");
|
||||
else
|
||||
params = null;
|
||||
}
|
||||
|
||||
String method;
|
||||
long id;
|
||||
JSONObject params;
|
||||
}
|
||||
|
||||
|
||||
class RPCNotification {
|
||||
RPCNotification(JSONObject json) throws JSONException {
|
||||
fromJson(json);
|
||||
}
|
||||
|
||||
RPCNotification(String json) throws JSONException {
|
||||
this(new JSONObject(json));
|
||||
}
|
||||
|
||||
RPCNotification(String method, long id, JSONObject params) {
|
||||
this.method = method;
|
||||
this.params = params;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return toJson().toString();
|
||||
}
|
||||
|
||||
JSONObject toJson() {
|
||||
JSONObject request = new JSONObject();
|
||||
try {
|
||||
request.put("jsonrpc", "2.0");
|
||||
request.put("method", method);
|
||||
if (params != null)
|
||||
request.put("params", params);
|
||||
return request;
|
||||
} catch (JSONException e) {
|
||||
e.printStackTrace();
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
void fromJson(JSONObject json) throws JSONException {
|
||||
method = json.getString("method");
|
||||
if (json.has("params"))
|
||||
params = json.getJSONObject("params");
|
||||
else
|
||||
params = null;
|
||||
}
|
||||
|
||||
String method;
|
||||
JSONObject params;
|
||||
}
|
||||
|
||||
|
||||
class RPCResponse {
|
||||
RPCResponse(JSONObject json) throws JSONException {
|
||||
fromJson(json);
|
||||
}
|
||||
|
||||
RPCResponse(String json) throws JSONException {
|
||||
this(new JSONObject(json));
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return toJson().toString();
|
||||
}
|
||||
|
||||
JSONObject toJson() {
|
||||
JSONObject response = new JSONObject();
|
||||
try {
|
||||
response.put("jsonrpc", "2.0");
|
||||
if (error != null)
|
||||
response.put("error", error);
|
||||
else if (result != null)
|
||||
response.put("result", result);
|
||||
else
|
||||
throw new JSONException("error and result are null");
|
||||
|
||||
response.put("id", id);
|
||||
return response;
|
||||
} catch (JSONException e) {
|
||||
e.printStackTrace();
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
void fromJson(JSONObject json) throws JSONException {
|
||||
id = json.getLong("id");
|
||||
if (json.has("error")) {
|
||||
error = json.getJSONObject("error");
|
||||
result = null;
|
||||
}
|
||||
else if (json.has("result")) {
|
||||
result = json.getJSONObject("result");
|
||||
error = null;
|
||||
}
|
||||
else
|
||||
throw new JSONException("error and result are null");
|
||||
}
|
||||
|
||||
long id;
|
||||
JSONObject result;
|
||||
JSONObject error;
|
||||
}
|
||||
|
|
@ -1,413 +0,0 @@
|
|||
/*
|
||||
* This file is part of snapcast
|
||||
* Copyright (C) 2014-2017 Johannes Pohl
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package de.badaix.snapcast.control;
|
||||
|
||||
import android.util.Log;
|
||||
|
||||
import org.json.JSONArray;
|
||||
import org.json.JSONException;
|
||||
import org.json.JSONObject;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
|
||||
import de.badaix.snapcast.control.json.Client;
|
||||
import de.badaix.snapcast.control.json.Group;
|
||||
import de.badaix.snapcast.control.json.ServerStatus;
|
||||
import de.badaix.snapcast.control.json.Stream;
|
||||
import de.badaix.snapcast.control.json.Volume;
|
||||
|
||||
/**
|
||||
* Created by johannes on 13.01.16.
|
||||
*/
|
||||
public class RemoteControl implements TcpClient.TcpClientListener {
|
||||
|
||||
public enum RPCEvent {
|
||||
response,
|
||||
notification
|
||||
}
|
||||
|
||||
private static final String TAG = "RC";
|
||||
|
||||
private TcpClient tcpClient;
|
||||
private long msgId;
|
||||
private RemoteControlListener listener;
|
||||
private String host;
|
||||
private int port;
|
||||
private final HashMap<Long, String> pendingRequests;
|
||||
|
||||
public RemoteControl(RemoteControlListener listener) {
|
||||
this.listener = listener;
|
||||
msgId = 0;
|
||||
pendingRequests = new HashMap<>();
|
||||
}
|
||||
|
||||
public String getHost() {
|
||||
return host;
|
||||
}
|
||||
|
||||
|
||||
public int getPort() {
|
||||
return port;
|
||||
}
|
||||
|
||||
|
||||
public synchronized void connect(final String host, final int port) {
|
||||
if ((tcpClient != null) && tcpClient.isConnected()) {
|
||||
if (this.host.equals(host) && (this.port == port))
|
||||
return;
|
||||
else
|
||||
disconnect();
|
||||
}
|
||||
this.host = host;
|
||||
this.port = port;
|
||||
|
||||
tcpClient = new TcpClient(this);
|
||||
tcpClient.start(host, port);
|
||||
}
|
||||
|
||||
public void disconnect() {
|
||||
if ((tcpClient != null) && (tcpClient.isConnected()))
|
||||
tcpClient.stop();
|
||||
tcpClient = null;
|
||||
pendingRequests.clear();
|
||||
}
|
||||
|
||||
public boolean isConnected() {
|
||||
return ((tcpClient != null) && tcpClient.isConnected());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onMessageReceived(TcpClient tcpClient, String message) {
|
||||
try {
|
||||
if (message.trim().startsWith("[")) {
|
||||
JSONArray jsonArray = new JSONArray(message);
|
||||
for (int i = 0; i < jsonArray.length(); ++i) {
|
||||
JSONObject json = jsonArray.getJSONObject(i);
|
||||
processJson(json);
|
||||
}
|
||||
} else {
|
||||
JSONObject json = new JSONObject(message);
|
||||
processJson(json);
|
||||
}
|
||||
} catch (JSONException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
private void processJson(JSONObject json) {
|
||||
// Log.d(TAG, "Msg received: " + message);
|
||||
try {
|
||||
|
||||
if (json.has("id")) {
|
||||
/// Response
|
||||
RPCResponse response = new RPCResponse(json);
|
||||
// Log.d(TAG, "ID: " + json.getString("id"));
|
||||
RPCRequest request = null;
|
||||
synchronized (pendingRequests) {
|
||||
if (pendingRequests.containsKey(response.id)) {
|
||||
request = new RPCRequest(new JSONObject(pendingRequests.get(response.id)));
|
||||
Log.d(TAG, "Response to: " + request.method);
|
||||
pendingRequests.remove(response.id);
|
||||
}
|
||||
}
|
||||
|
||||
if (listener == null)
|
||||
return;
|
||||
|
||||
if (json.has("error")) {
|
||||
JSONObject error = json.getJSONObject("error");
|
||||
Log.e(TAG, "error " + error.getInt("code") + ": " + error.getString("message") + "; data: " + error.getString("data"));
|
||||
}
|
||||
|
||||
if (request == null) {
|
||||
Log.e(TAG, "request for id " + response.id + " not found");
|
||||
return;
|
||||
}
|
||||
|
||||
RPCEvent rpcEvent = RPCEvent.response;
|
||||
/// Response to a "Object.GetStatus" message
|
||||
if (request.method.equals("Client.GetStatus")) {
|
||||
listener.onUpdate(new Client(response.result.getJSONObject("client")));
|
||||
} else if (request.method.equals("Client.SetVolume")) {
|
||||
} else if (request.method.equals("Client.SetLatency")) {
|
||||
} else if (request.method.equals("Client.SetName")) {
|
||||
} else if (request.method.equals("Group.GetStatus")) {
|
||||
listener.onUpdate(new Group(response.result.getJSONObject("group")));
|
||||
} else if (request.method.equals("Group.SetMute")) {
|
||||
// listener.onMute(rpcEvent, request.params.getString("id"), response.result.getBoolean("mute"));
|
||||
} else if (request.method.equals("Group.SetStream")) {
|
||||
} else if (request.method.equals("Group.SetClients")) {
|
||||
listener.onUpdate(new ServerStatus(response.result.getJSONObject("server")));
|
||||
} else if (request.method.equals("Server.GetStatus")) {
|
||||
listener.onUpdate(new ServerStatus(response.result.getJSONObject("server")));
|
||||
} else if (request.method.equals("Server.DeleteClient")) {
|
||||
listener.onUpdate(new ServerStatus(response.result.getJSONObject("server")));
|
||||
}
|
||||
} else {
|
||||
/// Notification
|
||||
if (listener == null)
|
||||
return;
|
||||
RPCEvent rpcEvent = RPCEvent.notification;
|
||||
RPCNotification notification = new RPCNotification(json);
|
||||
|
||||
if (notification.method.equals("Client.OnConnect")) {
|
||||
listener.onConnect(new Client(notification.params.getJSONObject("client")));
|
||||
} else if (notification.method.equals("Client.OnDisconnect")) {
|
||||
listener.onDisconnect(notification.params.getString("id"));
|
||||
} else if (notification.method.equals("Client.OnVolumeChanged")) {
|
||||
listener.onVolumeChanged(rpcEvent, notification.params.getString("id"), new Volume(notification.params.getJSONObject("volume")));
|
||||
} else if (notification.method.equals("Client.OnLatencyChanged")) {
|
||||
listener.onLatencyChanged(rpcEvent, notification.params.getString("id"), notification.params.getInt("latency"));
|
||||
} else if (notification.method.equals("Client.OnNameChanged")) {
|
||||
listener.onNameChanged(rpcEvent, notification.params.getString("id"), notification.params.getString("name"));
|
||||
} else if (notification.method.equals("Group.OnMute")) {
|
||||
listener.onMute(rpcEvent, notification.params.getString("id"), notification.params.getBoolean("mute"));
|
||||
} else if (notification.method.equals("Group.OnStreamChanged")) {
|
||||
listener.onStreamChanged(rpcEvent, notification.params.getString("id"), notification.params.getString("stream_id"));
|
||||
} else if (notification.method.equals("Stream.OnUpdate")) {
|
||||
listener.onUpdate(notification.params.getString("id"), new Stream(notification.params.getJSONObject("stream")));
|
||||
} else if (notification.method.equals("Group.OnUpdate")) {
|
||||
listener.onUpdate(new Group(notification.params.getJSONObject("group")));
|
||||
} else if (notification.method.equals("Server.OnUpdate")) {
|
||||
listener.onUpdate(new ServerStatus(notification.params.getJSONObject("server")));
|
||||
}
|
||||
}
|
||||
|
||||
} catch (JSONException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onConnecting(TcpClient tcpClient) {
|
||||
Log.d(TAG, "onConnecting");
|
||||
if (listener != null)
|
||||
listener.onConnecting(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onConnected(TcpClient tcpClient) {
|
||||
Log.d(TAG, "onConnected");
|
||||
if (listener != null)
|
||||
listener.onConnected(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDisconnected(TcpClient tcpClient, Exception e) {
|
||||
Log.d(TAG, "onDisconnected");
|
||||
if (listener != null)
|
||||
listener.onDisconnected(this, e);
|
||||
}
|
||||
|
||||
private RPCRequest jsonRequest(String method, JSONObject params) {
|
||||
RPCRequest request = new RPCRequest(method, msgId, params);
|
||||
synchronized (pendingRequests) {
|
||||
pendingRequests.put(msgId, request.toString());
|
||||
}
|
||||
msgId++;
|
||||
return request;
|
||||
}
|
||||
|
||||
public void getServerStatus() {
|
||||
RPCRequest request = jsonRequest("Server.GetStatus", null);
|
||||
tcpClient.sendMessage(request.toString());
|
||||
}
|
||||
|
||||
public void setName(Client client, String name) {
|
||||
try {
|
||||
JSONObject params = new JSONObject();
|
||||
params.put("id", client.getId());
|
||||
params.put("name", name);
|
||||
RPCRequest request = jsonRequest("Client.SetName", params);
|
||||
tcpClient.sendMessage(request.toString());
|
||||
} catch (JSONException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
public void setLatency(Client client, int latency) {
|
||||
try {
|
||||
JSONObject params = new JSONObject();
|
||||
params.put("id", client.getId());
|
||||
params.put("latency", latency);
|
||||
RPCRequest request = jsonRequest("Client.SetLatency", params);
|
||||
tcpClient.sendMessage(request.toString());
|
||||
} catch (JSONException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
public void setStream(Group group, String id) {
|
||||
setStream(group.getId(), id);
|
||||
}
|
||||
|
||||
public void setClients(String groupId, ArrayList<String> clientIds) {
|
||||
try {
|
||||
JSONArray clients = new JSONArray();
|
||||
for (String clientId : clientIds)
|
||||
clients.put(clientId);
|
||||
JSONObject params = new JSONObject();
|
||||
params.put("id", groupId);
|
||||
params.put("clients", clients);
|
||||
RPCRequest request = jsonRequest("Group.SetClients", params);
|
||||
tcpClient.sendMessage(request.toString());
|
||||
} catch (JSONException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
public void setStream(String groupId, String streamId) {
|
||||
try {
|
||||
JSONObject params = new JSONObject();
|
||||
params.put("id", groupId);
|
||||
params.put("stream_id", streamId);
|
||||
RPCRequest request = jsonRequest("Group.SetStream", params);
|
||||
tcpClient.sendMessage(request.toString());
|
||||
} catch (JSONException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
public void setGroupMuted(Group group, boolean muted) {
|
||||
try {
|
||||
JSONObject params = new JSONObject();
|
||||
params.put("id", group.getId());
|
||||
params.put("mute", muted);
|
||||
RPCRequest request = jsonRequest("Group.SetMute", params);
|
||||
tcpClient.sendMessage(request.toString());
|
||||
} catch (JSONException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
public void setGroupVolume(Group group) {
|
||||
try {
|
||||
JSONArray batch = new JSONArray();
|
||||
for (Client client : group.getClients()) {
|
||||
Volume volume = client.getConfig().getVolume();
|
||||
RPCRequest volumeRequest = getVolumeRequest(client, volume.getPercent(), volume.isMuted());
|
||||
batch.put(volumeRequest.toJson());
|
||||
}
|
||||
tcpClient.sendMessage(batch.toString());
|
||||
} catch (JSONException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
private RPCRequest getVolumeRequest(Client client, int percent, boolean mute) throws JSONException {
|
||||
Volume volume = new Volume(percent, mute);
|
||||
JSONObject params = new JSONObject();
|
||||
params.put("id", client.getId());
|
||||
params.put("volume", volume.toJson());
|
||||
return jsonRequest("Client.SetVolume", params);
|
||||
}
|
||||
|
||||
public void setVolume(Client client, int percent, boolean mute) {
|
||||
try {
|
||||
tcpClient.sendMessage(getVolumeRequest(client, percent, mute).toString());
|
||||
} catch (JSONException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
public void delete(Client client) {
|
||||
try {
|
||||
JSONObject params = new JSONObject();
|
||||
params.put("id", client.getId());
|
||||
RPCRequest request = jsonRequest("Server.DeleteClient", params);
|
||||
tcpClient.sendMessage(request.toString());
|
||||
} catch (JSONException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
public enum ClientEvent {
|
||||
connected("Client.OnConnect"),
|
||||
disconnected("Client.OnDisconnect"),
|
||||
updated("Client.OnUpdate");
|
||||
//deleted("Client.OnDelete");
|
||||
private String text;
|
||||
|
||||
ClientEvent(String text) {
|
||||
this.text = text;
|
||||
}
|
||||
|
||||
public static ClientEvent fromString(String text) {
|
||||
if (text != null) {
|
||||
for (ClientEvent b : ClientEvent.values()) {
|
||||
if (text.equalsIgnoreCase(b.text)) {
|
||||
return b;
|
||||
}
|
||||
}
|
||||
}
|
||||
throw new IllegalArgumentException("No ClientEvent with text " + text + " found");
|
||||
}
|
||||
|
||||
public String getText() {
|
||||
return this.text;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public interface ClientListener {
|
||||
void onConnect(Client client);
|
||||
void onDisconnect(String clientId);
|
||||
void onUpdate(Client client);
|
||||
void onVolumeChanged(RPCEvent event, String clientId, Volume volume);
|
||||
void onLatencyChanged(RPCEvent event, String clientId, long latency);
|
||||
void onNameChanged(RPCEvent event, String clientId, String name);
|
||||
}
|
||||
|
||||
public interface GroupListener {
|
||||
void onUpdate(Group group);
|
||||
void onMute(RPCEvent event, String groupId, boolean mute);
|
||||
void onStreamChanged(RPCEvent event, String groupId, String streamId);
|
||||
}
|
||||
|
||||
public interface StreamListener {
|
||||
void onUpdate(String streamId, Stream stream);
|
||||
}
|
||||
|
||||
public interface ServerListener {
|
||||
void onUpdate(ServerStatus server);
|
||||
}
|
||||
|
||||
|
||||
|
||||
public interface RemoteControlListener extends ServerListener, StreamListener, GroupListener, ClientListener {
|
||||
void onConnected(RemoteControl remoteControl);
|
||||
|
||||
void onConnecting(RemoteControl remoteControl);
|
||||
|
||||
void onDisconnected(RemoteControl remoteControl, Exception e);
|
||||
|
||||
void onBatchStart();
|
||||
void onBatchEnd();
|
||||
/*
|
||||
void onClientEvent(RemoteControl remoteControl, RPCEvent rpcEvent, Client client, ClientEvent event);
|
||||
|
||||
void onServerUpdate(RemoteControl remoteControl, RPCEvent rpcEvent, ServerStatus serverStatus);
|
||||
|
||||
void onStreamUpdate(RemoteControl remoteControl, RPCEvent rpcEvent, Stream stream);
|
||||
|
||||
void onGroupUpdate(RemoteControl remoteControl, RPCEvent rpcEvent, Group group);
|
||||
*/
|
||||
}
|
||||
}
|
|
@ -1,228 +0,0 @@
|
|||
/*
|
||||
* This file is part of snapcast
|
||||
* Copyright (C) 2014-2017 Johannes Pohl
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package de.badaix.snapcast.control;
|
||||
|
||||
import android.util.Log;
|
||||
|
||||
import java.io.BufferedReader;
|
||||
import java.io.BufferedWriter;
|
||||
import java.io.InputStreamReader;
|
||||
import java.io.OutputStreamWriter;
|
||||
import java.io.PrintWriter;
|
||||
import java.net.InetAddress;
|
||||
import java.net.Socket;
|
||||
import java.util.concurrent.BlockingQueue;
|
||||
import java.util.concurrent.LinkedBlockingQueue;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
/**
|
||||
* Created by johannes on 06.01.16.
|
||||
*/
|
||||
public class TcpClient {
|
||||
|
||||
private static final String TAG = "TCP";
|
||||
private String mServerMessage;
|
||||
// sends message received notifications
|
||||
private TcpClientListener mMessageListener = null;
|
||||
// while this is true, the server will continue running
|
||||
private boolean mRun = false;
|
||||
// used to send messages
|
||||
private PrintWriter mBufferOut;
|
||||
// used to read messages from the server
|
||||
private BufferedReader mBufferIn;
|
||||
private Thread readerThread = null;
|
||||
private Socket socket = null;
|
||||
private BlockingQueue<String> messages = new LinkedBlockingQueue<>();
|
||||
|
||||
/**
|
||||
* Constructor of the class. OnMessagedReceived listens for the messages
|
||||
* received from server
|
||||
*/
|
||||
public TcpClient(TcpClientListener listener) {
|
||||
mMessageListener = listener;
|
||||
}
|
||||
|
||||
public boolean isConnected() {
|
||||
if (socket == null)
|
||||
return false;
|
||||
return socket.isConnected();
|
||||
}
|
||||
|
||||
/**
|
||||
* Sends the message entered by client to the server
|
||||
*
|
||||
* @param message text entered by client
|
||||
*/
|
||||
public void sendMessage(final String message) {
|
||||
messages.offer(message);
|
||||
}
|
||||
|
||||
/**
|
||||
* Close the connection and release the members
|
||||
*/
|
||||
public void stop() {
|
||||
mRun = false;
|
||||
|
||||
if (mBufferOut != null) {
|
||||
mBufferOut.flush();
|
||||
mBufferOut.close();
|
||||
}
|
||||
|
||||
// mMessageListener = null;
|
||||
readerThread.interrupt();
|
||||
try {
|
||||
readerThread.join(1000);
|
||||
} catch (InterruptedException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
mBufferIn = null;
|
||||
mBufferOut = null;
|
||||
mServerMessage = null;
|
||||
}
|
||||
|
||||
public void start(final String host, final int port) {
|
||||
ReaderRunnable readerRunnable = new ReaderRunnable(host, port);
|
||||
readerThread = new Thread(readerRunnable);
|
||||
readerThread.start();
|
||||
}
|
||||
|
||||
// Declare the interface. The method messageReceived(String message) will
|
||||
// must be implemented in the MyActivity
|
||||
// class at on asynckTask doInBackground
|
||||
interface TcpClientListener {
|
||||
void onMessageReceived(TcpClient tcpClient, String message);
|
||||
|
||||
void onConnecting(TcpClient tcpClient);
|
||||
|
||||
void onConnected(TcpClient tcpClient);
|
||||
|
||||
void onDisconnected(TcpClient tcpClient, Exception e);
|
||||
}
|
||||
|
||||
|
||||
private class WriterRunnable implements Runnable {
|
||||
@Override
|
||||
public void run() {
|
||||
while (mRun) {
|
||||
try {
|
||||
String message = messages.poll(50, TimeUnit.MILLISECONDS);
|
||||
if ((message != null) && (mBufferOut != null)) {
|
||||
Log.d(TAG, "Sending: " + message);
|
||||
mBufferOut.println(message + "\r\n");
|
||||
mBufferOut.flush();
|
||||
}
|
||||
} catch (InterruptedException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private class ReaderRunnable implements Runnable {
|
||||
private String host;
|
||||
private int port;
|
||||
|
||||
ReaderRunnable(final String host, final int port) {
|
||||
this.host = host;
|
||||
this.port = port;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
mRun = true;
|
||||
Exception exception = null;
|
||||
Thread writerThread = null;
|
||||
|
||||
try {
|
||||
if (mMessageListener != null)
|
||||
mMessageListener.onConnecting(TcpClient.this);
|
||||
|
||||
// here you must put your computer's IP address.
|
||||
InetAddress serverAddr = InetAddress.getByName(host);
|
||||
|
||||
Log.d(TAG, "Connecting to " + serverAddr.getCanonicalHostName() + ":" + port);
|
||||
|
||||
// create a socket to make the connection with the server
|
||||
socket = new Socket(serverAddr, port);
|
||||
|
||||
|
||||
// sends the message to the server
|
||||
mBufferOut = new PrintWriter(new BufferedWriter(
|
||||
new OutputStreamWriter(socket.getOutputStream())), true);
|
||||
|
||||
// receives the message which the server sends back
|
||||
mBufferIn = new BufferedReader(new InputStreamReader(
|
||||
socket.getInputStream()));
|
||||
|
||||
if (mMessageListener != null)
|
||||
mMessageListener.onConnected(TcpClient.this);
|
||||
|
||||
writerThread = new Thread(new WriterRunnable());
|
||||
writerThread.start();
|
||||
|
||||
// in this while the client listens for the messages sent by the
|
||||
// server
|
||||
while (mRun) {
|
||||
|
||||
mServerMessage = mBufferIn.readLine();
|
||||
|
||||
if (mServerMessage != null) {
|
||||
Log.d(TAG, "Received Message: '" + mServerMessage + "'");
|
||||
if (mMessageListener != null) {
|
||||
mMessageListener.onMessageReceived(TcpClient.this, mServerMessage);
|
||||
}
|
||||
} else {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
} catch (Exception e) {
|
||||
Log.d(TAG, "Error", e);
|
||||
exception = e;
|
||||
} finally {
|
||||
// the socket must be closed. It is not possible to reconnect to
|
||||
// this socket
|
||||
// after it is closed, which means a new socket instance has to
|
||||
// be created.
|
||||
mRun = false;
|
||||
if (writerThread != null) {
|
||||
try {
|
||||
writerThread.interrupt();
|
||||
writerThread.join(100);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
if (socket != null) {
|
||||
try {
|
||||
socket.close();
|
||||
} catch (Exception ignored) {
|
||||
}
|
||||
}
|
||||
socket = null;
|
||||
if (mMessageListener != null)
|
||||
mMessageListener.onDisconnected(TcpClient.this, exception);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -1,163 +0,0 @@
|
|||
/*
|
||||
* This file is part of snapcast
|
||||
* Copyright (C) 2014-2017 Johannes Pohl
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package de.badaix.snapcast.control.json;
|
||||
|
||||
import org.json.JSONException;
|
||||
import org.json.JSONObject;
|
||||
|
||||
/**
|
||||
* Created by johannes on 06.01.16.
|
||||
*/
|
||||
public class Client implements JsonSerialisable, Comparable<Client> {
|
||||
private Host host;
|
||||
private Snapclient snapclient;
|
||||
private ClientConfig config;
|
||||
private Time_t lastSeen;
|
||||
private boolean connected;
|
||||
private String clientId;
|
||||
private boolean deleted = false;
|
||||
|
||||
public Client(JSONObject json) {
|
||||
fromJson(json);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void fromJson(JSONObject json) {
|
||||
try {
|
||||
host = new Host(json.getJSONObject("host"));
|
||||
snapclient = new Snapclient(json.getJSONObject("snapclient"));
|
||||
config = new ClientConfig(json.getJSONObject("config"));
|
||||
|
||||
lastSeen = new Time_t(json.getJSONObject("lastSeen"));
|
||||
connected = json.getBoolean("connected");
|
||||
clientId = json.optString("id", host.mac);
|
||||
} catch (JSONException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public JSONObject toJson() {
|
||||
JSONObject json = new JSONObject();
|
||||
try {
|
||||
json.put("host", host.toJson());
|
||||
json.put("snapclient", snapclient.toJson());
|
||||
json.put("config", config.toJson());
|
||||
json.put("lastSeen", lastSeen.toJson());
|
||||
json.put("connected", connected);
|
||||
json.put("id", clientId);
|
||||
} catch (JSONException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return json;
|
||||
}
|
||||
|
||||
public Host getHost() {
|
||||
return host;
|
||||
}
|
||||
|
||||
public Snapcast getSnapclient() {
|
||||
return snapclient;
|
||||
}
|
||||
|
||||
public ClientConfig getConfig() {
|
||||
return config;
|
||||
}
|
||||
|
||||
public Time_t getLastSeen() {
|
||||
return lastSeen;
|
||||
}
|
||||
|
||||
public void setVolume(Volume volume) {
|
||||
this.config.setVolume(volume);
|
||||
}
|
||||
|
||||
public void setName(String name) {
|
||||
this.config.setName(name);
|
||||
}
|
||||
|
||||
public String getVisibleName() {
|
||||
if ((config.getName() != null) && !config.getName().isEmpty())
|
||||
return config.getName();
|
||||
String name = host.getName();
|
||||
if (config.getInstance() > 1)
|
||||
name += " #" + config.getInstance();
|
||||
return name;
|
||||
}
|
||||
|
||||
public boolean isConnected() {
|
||||
return connected;
|
||||
}
|
||||
|
||||
public void setConnected(boolean connected) {
|
||||
this.connected = connected;
|
||||
}
|
||||
|
||||
public String getId() {
|
||||
return clientId;
|
||||
}
|
||||
|
||||
public boolean isDeleted() {
|
||||
return deleted;
|
||||
}
|
||||
|
||||
public void setDeleted(boolean deleted) {
|
||||
this.deleted = deleted;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return toJson().toString();
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
if (this == o) return true;
|
||||
if (o == null || getClass() != o.getClass()) return false;
|
||||
|
||||
Client that = (Client) o;
|
||||
|
||||
if (host != null ? !host.equals(that.host) : that.host != null) return false;
|
||||
if (snapclient != null ? !snapclient.equals(that.snapclient) : that.snapclient != null)
|
||||
return false;
|
||||
if (config != null ? !config.equals(that.config) : that.config != null) return false;
|
||||
if (connected != that.connected) return false;
|
||||
if (clientId != null ? !clientId.equals(that.clientId) : that.clientId != null)
|
||||
return false;
|
||||
return (deleted == that.deleted);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
int result = host != null ? host.hashCode() : 0;
|
||||
result = 31 * result + (snapclient != null ? snapclient.hashCode() : 0);
|
||||
result = 31 * result + (config != null ? config.hashCode() : 0);
|
||||
result = 31 * result + (connected ? 1 : 0);
|
||||
result = 31 * result + (clientId != null ? clientId.hashCode() : 0);
|
||||
result = 31 * result + (deleted ? 1 : 0);
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int compareTo(Client another) {
|
||||
return getVisibleName().compareToIgnoreCase(another.getVisibleName());
|
||||
}
|
||||
}
|
||||
|
|
@ -1,123 +0,0 @@
|
|||
/*
|
||||
* This file is part of snapcast
|
||||
* Copyright (C) 2014-2017 Johannes Pohl
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package de.badaix.snapcast.control.json;
|
||||
|
||||
import org.json.JSONException;
|
||||
import org.json.JSONObject;
|
||||
|
||||
/**
|
||||
* Created by johannes on 06.01.16.
|
||||
*/
|
||||
public class ClientConfig implements JsonSerialisable {
|
||||
String name = "";
|
||||
Volume volume;
|
||||
int latency = 0;
|
||||
int instance = 1;
|
||||
|
||||
public ClientConfig() {
|
||||
volume = new Volume();
|
||||
}
|
||||
|
||||
public ClientConfig(JSONObject json) {
|
||||
fromJson(json);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void fromJson(JSONObject json) {
|
||||
try {
|
||||
name = json.getString("name");
|
||||
volume = new Volume(json.getJSONObject("volume"));
|
||||
latency = json.getInt("latency");
|
||||
instance = json.getInt("instance");
|
||||
} catch (JSONException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public JSONObject toJson() {
|
||||
JSONObject json = new JSONObject();
|
||||
try {
|
||||
json.put("name", name);
|
||||
json.put("volume", volume.toJson());
|
||||
json.put("latency", latency);
|
||||
json.put("instance", instance);
|
||||
} catch (JSONException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return json;
|
||||
}
|
||||
|
||||
public Volume getVolume() {
|
||||
return volume;
|
||||
}
|
||||
|
||||
public void setVolume(Volume volume) {
|
||||
this.volume = volume;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public void setName(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public int getLatency() {
|
||||
return latency;
|
||||
}
|
||||
|
||||
public void setLatency(int latency) {
|
||||
this.latency = latency;
|
||||
}
|
||||
|
||||
public int getInstance() {
|
||||
return instance;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return toJson().toString();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
if (this == o) return true;
|
||||
if (o == null || getClass() != o.getClass()) return false;
|
||||
|
||||
ClientConfig that = (ClientConfig) o;
|
||||
|
||||
if (latency != that.latency) return false;
|
||||
if (name != null ? !name.equals(that.name) : that.name != null) return false;
|
||||
if (instance != that.instance) return false;
|
||||
return !(volume != null ? !volume.equals(that.volume) : that.volume != null);
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
int result = name != null ? name.hashCode() : 0;
|
||||
result = 31 * result + (volume != null ? volume.hashCode() : 0);
|
||||
result = 31 * result + latency;
|
||||
result = 31 * result + instance;
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
|
@ -1,214 +0,0 @@
|
|||
/*
|
||||
* This file is part of snapcast
|
||||
* Copyright (C) 2014-2017 Johannes Pohl
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package de.badaix.snapcast.control.json;
|
||||
|
||||
import android.support.annotation.NonNull;
|
||||
import android.text.TextUtils;
|
||||
|
||||
import org.json.JSONArray;
|
||||
import org.json.JSONException;
|
||||
import org.json.JSONObject;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
|
||||
|
||||
/**
|
||||
* Created by johannes on 03.12.16.
|
||||
*/
|
||||
|
||||
public class Group implements JsonSerialisable, Comparable<Group> {
|
||||
private String name = "";
|
||||
private String id = "";
|
||||
private String streamId = "";
|
||||
private boolean muted = false;
|
||||
private ArrayList<Client> clients = new ArrayList<Client>();
|
||||
|
||||
public Group(JSONObject json) {
|
||||
fromJson(json);
|
||||
}
|
||||
|
||||
public Group() {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void fromJson(JSONObject json) {
|
||||
try {
|
||||
clients.clear();
|
||||
name = json.getString("name");
|
||||
id = json.getString("id");
|
||||
streamId = json.getString("stream_id");
|
||||
muted = json.optBoolean("muted", false);
|
||||
JSONArray jClients = json.optJSONArray("clients");
|
||||
if (jClients != null) {
|
||||
for (int i = 0; i < jClients.length(); i++)
|
||||
clients.add(new Client(jClients.getJSONObject(i)));
|
||||
}
|
||||
} catch (JSONException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
sort();
|
||||
}
|
||||
|
||||
@Override
|
||||
public JSONObject toJson() {
|
||||
JSONObject json = new JSONObject();
|
||||
try {
|
||||
json.put("name", name);
|
||||
json.put("id", id);
|
||||
json.put("stream_id", streamId);
|
||||
json.put("muted", muted);
|
||||
json.put("clients", getJsonClients());
|
||||
} catch (JSONException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return json;
|
||||
}
|
||||
|
||||
public void sort() {
|
||||
Collections.sort(clients);
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
|
||||
return name;
|
||||
}
|
||||
|
||||
public void setName(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public String getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public void setId(String id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public String getStreamId() {
|
||||
return streamId;
|
||||
}
|
||||
|
||||
public void setStreamId(String streamId) {
|
||||
this.streamId = streamId;
|
||||
}
|
||||
|
||||
public ArrayList<Client> getClients() {
|
||||
return clients;
|
||||
}
|
||||
|
||||
public boolean isMuted() {
|
||||
return muted;
|
||||
}
|
||||
|
||||
public void setMuted(boolean muted) {
|
||||
this.muted = muted;
|
||||
}
|
||||
|
||||
public boolean removeClient(String id) {
|
||||
if (TextUtils.isEmpty(id))
|
||||
return false;
|
||||
|
||||
for (int i = 0; i < clients.size(); ++i) {
|
||||
if (clients.get(i).getId().equals(id)) {
|
||||
clients.remove(i);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
boolean updateClient(Client client) {
|
||||
if (client == null)
|
||||
return false;
|
||||
|
||||
for (int i = 0; i < clients.size(); ++i) {
|
||||
Client c = clients.get(i);
|
||||
if (c == null)
|
||||
continue;
|
||||
|
||||
if (client.getId().equals(c.getId())) {
|
||||
if (client.equals(c))
|
||||
return true;
|
||||
clients.set(i, client);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
public Client getClient(String id) {
|
||||
if (TextUtils.isEmpty(id))
|
||||
return null;
|
||||
|
||||
for (Client c : clients) {
|
||||
if (c == null)
|
||||
continue;
|
||||
|
||||
if (id.equals(c.getId()))
|
||||
return c;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public JSONArray getJsonClients() {
|
||||
JSONArray jsonArray = new JSONArray();
|
||||
for (Client client : clients)
|
||||
jsonArray.put(client.toJson());
|
||||
return jsonArray;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
if (this == o) return true;
|
||||
if (o == null || getClass() != o.getClass()) return false;
|
||||
|
||||
Group group = (Group) o;
|
||||
|
||||
if (name != null ? !name.equals(group.name) : group.name != null) return false;
|
||||
if (id != null ? !id.equals(group.id) : group.id != null) return false;
|
||||
if (muted != group.muted) return false;
|
||||
if (streamId != null ? !streamId.equals(group.streamId) : group.streamId != null)
|
||||
return false;
|
||||
return clients != null ? clients.equals(group.clients) : group.clients == null;
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
int result = name != null ? name.hashCode() : 0;
|
||||
result = 31 * result + (id != null ? id.hashCode() : 0);
|
||||
result = 31 * result + (streamId != null ? streamId.hashCode() : 0);
|
||||
result = 31 * result + (muted ? 1 : 0);
|
||||
result = 31 * result + (clients != null ? clients.hashCode() : 0);
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int compareTo(@NonNull Group another) {
|
||||
if (getClients().isEmpty())
|
||||
return -1;
|
||||
if (another.getClients().isEmpty())
|
||||
return 1;
|
||||
return getClients().get(0).compareTo(another.getClients().get(0));
|
||||
}
|
||||
}
|
|
@ -1,119 +0,0 @@
|
|||
/*
|
||||
* This file is part of snapcast
|
||||
* Copyright (C) 2014-2017 Johannes Pohl
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package de.badaix.snapcast.control.json;
|
||||
|
||||
import org.json.JSONException;
|
||||
import org.json.JSONObject;
|
||||
|
||||
/**
|
||||
* Created by johannes on 06.01.16.
|
||||
*/
|
||||
public class Host implements JsonSerialisable {
|
||||
String name = "";
|
||||
String mac = "";
|
||||
String os = "";
|
||||
String arch = "";
|
||||
String ip = "";
|
||||
|
||||
public Host(JSONObject json) {
|
||||
fromJson(json);
|
||||
}
|
||||
|
||||
public Host() {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void fromJson(JSONObject json) {
|
||||
try {
|
||||
name = json.getString("name");
|
||||
mac = json.getString("mac");
|
||||
os = json.getString("os");
|
||||
arch = json.getString("arch");
|
||||
ip = json.getString("ip");
|
||||
} catch (JSONException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public JSONObject toJson() {
|
||||
JSONObject json = new JSONObject();
|
||||
try {
|
||||
json.put("name", name);
|
||||
json.put("mac", mac);
|
||||
json.put("os", os);
|
||||
json.put("arch", arch);
|
||||
json.put("ip", ip);
|
||||
} catch (JSONException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return json;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public String getMac() {
|
||||
return mac;
|
||||
}
|
||||
|
||||
public String getOs() {
|
||||
return os;
|
||||
}
|
||||
|
||||
public String getArch() {
|
||||
return arch;
|
||||
}
|
||||
|
||||
public String getIp() {
|
||||
return ip;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return toJson().toString();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
if (this == o) return true;
|
||||
if (o == null || getClass() != o.getClass()) return false;
|
||||
|
||||
Host that = (Host) o;
|
||||
|
||||
if (name != null ? !name.equals(that.name) : that.name != null) return false;
|
||||
if (mac != null ? !mac.equals(that.mac) : that.mac != null) return false;
|
||||
if (os != null ? !os.equals(that.os) : that.os != null) return false;
|
||||
if (arch != null ? !arch.equals(that.arch) : that.arch != null) return false;
|
||||
return !(ip != null ? !ip.equals(that.ip) : that.ip != null);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
int result = name != null ? name.hashCode() : 0;
|
||||
result = 31 * result + (mac != null ? mac.hashCode() : 0);
|
||||
result = 31 * result + (os != null ? os.hashCode() : 0);
|
||||
result = 31 * result + (arch != null ? arch.hashCode() : 0);
|
||||
result = 31 * result + (ip != null ? ip.hashCode() : 0);
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
|
@ -1,30 +0,0 @@
|
|||
/*
|
||||
* This file is part of snapcast
|
||||
* Copyright (C) 2014-2017 Johannes Pohl
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package de.badaix.snapcast.control.json;
|
||||
|
||||
import org.json.JSONObject;
|
||||
|
||||
/**
|
||||
* Created by johannes on 08.01.16.
|
||||
*/
|
||||
public interface JsonSerialisable {
|
||||
public void fromJson(JSONObject json);
|
||||
|
||||
public JSONObject toJson();
|
||||
}
|
|
@ -1,100 +0,0 @@
|
|||
/*
|
||||
* This file is part of snapcast
|
||||
* Copyright (C) 2014-2017 Johannes Pohl
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package de.badaix.snapcast.control.json;
|
||||
|
||||
import org.json.JSONException;
|
||||
import org.json.JSONObject;
|
||||
|
||||
/**
|
||||
* Created by johannes on 02.03.16.
|
||||
*/
|
||||
public class Server implements JsonSerialisable {
|
||||
private Host host;
|
||||
private Snapserver snapserver;
|
||||
|
||||
public Server(JSONObject json) {
|
||||
fromJson(json);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void fromJson(JSONObject json) {
|
||||
try {
|
||||
if (json.has("host") && !(json.get("host") instanceof String))
|
||||
host = new Host(json.getJSONObject("host"));
|
||||
else {
|
||||
host = new Host();
|
||||
host.name = json.getString("host");
|
||||
}
|
||||
|
||||
if (json.has("snapserver"))
|
||||
snapserver = new Snapserver(json.getJSONObject("snapserver"));
|
||||
else {
|
||||
snapserver = new Snapserver();
|
||||
snapserver.version = json.getString("version");
|
||||
}
|
||||
} catch (JSONException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public JSONObject toJson() {
|
||||
JSONObject json = new JSONObject();
|
||||
try {
|
||||
json.put("host", host.toJson());
|
||||
json.put("snapserver", snapserver.toJson());
|
||||
} catch (JSONException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return json;
|
||||
}
|
||||
|
||||
public Host getHost() {
|
||||
return host;
|
||||
}
|
||||
|
||||
public Snapcast getSnapserver() {
|
||||
return snapserver;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return toJson().toString();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
if (this == o) return true;
|
||||
if (o == null || getClass() != o.getClass()) return false;
|
||||
|
||||
Server server = (Server) o;
|
||||
|
||||
if (host != null ? !host.equals(server.host) : server.host != null) return false;
|
||||
return snapserver != null ? snapserver.equals(server.snapserver) : server.snapserver == null;
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
int result = host != null ? host.hashCode() : 0;
|
||||
result = 31 * result + (snapserver != null ? snapserver.hashCode() : 0);
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
|
@ -1,200 +0,0 @@
|
|||
/*
|
||||
* This file is part of snapcast
|
||||
* Copyright (C) 2014-2017 Johannes Pohl
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package de.badaix.snapcast.control.json;
|
||||
|
||||
import org.json.JSONArray;
|
||||
import org.json.JSONException;
|
||||
import org.json.JSONObject;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
|
||||
/**
|
||||
* Created by johannes on 06.01.16.
|
||||
*/
|
||||
public class ServerStatus implements JsonSerialisable {
|
||||
private ArrayList<Group> groups = new ArrayList<Group>();
|
||||
private ArrayList<Stream> streams = new ArrayList<Stream>();
|
||||
private Server server = null;
|
||||
|
||||
public ServerStatus(JSONObject json) {
|
||||
fromJson(json);
|
||||
}
|
||||
|
||||
public ServerStatus() {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void fromJson(JSONObject json) {
|
||||
try {
|
||||
clear();
|
||||
server = new Server(json.getJSONObject("server"));
|
||||
JSONArray jStreams = json.getJSONArray("streams");
|
||||
for (int i = 0; i < jStreams.length(); i++)
|
||||
streams.add(new Stream(jStreams.getJSONObject(i)));
|
||||
JSONArray jGroups = json.getJSONArray("groups");
|
||||
for (int i = 0; i < jGroups.length(); i++)
|
||||
groups.add(new Group(jGroups.getJSONObject(i)));
|
||||
} catch (JSONException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
sort();
|
||||
}
|
||||
|
||||
@Override
|
||||
public JSONObject toJson() {
|
||||
JSONObject json = new JSONObject();
|
||||
try {
|
||||
json.put("server", server.toJson());
|
||||
json.put("groups", getJsonGroups());
|
||||
json.put("streams", getJsonStreams());
|
||||
} catch (JSONException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return json;
|
||||
}
|
||||
|
||||
public void sort() {
|
||||
for (Group group : groups)
|
||||
group.sort();
|
||||
|
||||
Collections.sort(groups);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return toJson().toString();
|
||||
}
|
||||
|
||||
public void clear() {
|
||||
groups.clear();
|
||||
streams.clear();
|
||||
}
|
||||
|
||||
public boolean removeClient(Client client) {
|
||||
if (client == null)
|
||||
return false;
|
||||
|
||||
for (Group group : groups) {
|
||||
if (group.getClient(client.getId()) != null) {
|
||||
group.removeClient(client.getId());
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public boolean updateClient(Client client) {
|
||||
if (client == null)
|
||||
return false;
|
||||
|
||||
for (Group group : groups) {
|
||||
if (group.getClient(client.getId()) != null) {
|
||||
group.updateClient(client);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public boolean updateGroup(Group group) {
|
||||
if (group == null)
|
||||
return false;
|
||||
|
||||
for (int i = 0; i < groups.size(); ++i) {
|
||||
Group g = groups.get(i);
|
||||
if (g == null)
|
||||
continue;
|
||||
|
||||
if (group.getId().equals(g.getId())) {
|
||||
if (g.equals(group))
|
||||
return false;
|
||||
groups.set(i, group);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public boolean updateStream(Stream stream) {
|
||||
if (stream == null)
|
||||
return false;
|
||||
|
||||
for (int i = 0; i < streams.size(); ++i) {
|
||||
Stream s = streams.get(i);
|
||||
if (s == null)
|
||||
continue;
|
||||
|
||||
if (stream.getId().equals(s.getId())) {
|
||||
if (s.equals(stream))
|
||||
return false;
|
||||
streams.set(i, stream);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
streams.add(stream);
|
||||
return true;
|
||||
}
|
||||
|
||||
public Client getClient(String id) {
|
||||
for (Group group: groups) {
|
||||
Client client = group.getClient(id);
|
||||
if (client != null)
|
||||
return client;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public ArrayList<Group> getGroups() {
|
||||
return groups;
|
||||
}
|
||||
|
||||
public ArrayList<Stream> getStreams() {
|
||||
return streams;
|
||||
}
|
||||
|
||||
public Stream getStream(String id) {
|
||||
for (Stream s : streams)
|
||||
if ((s != null) && (s.getId().equals(id)))
|
||||
return s;
|
||||
return null;
|
||||
}
|
||||
|
||||
public Group getGroup(String id) {
|
||||
for (Group g : groups)
|
||||
if ((g != null) && (g.getId().equals(id)))
|
||||
return g;
|
||||
return null;
|
||||
}
|
||||
|
||||
public JSONArray getJsonStreams() {
|
||||
JSONArray jsonArray = new JSONArray();
|
||||
for (Stream stream : streams)
|
||||
jsonArray.put(stream.toJson());
|
||||
return jsonArray;
|
||||
}
|
||||
|
||||
public JSONArray getJsonGroups() {
|
||||
JSONArray jsonArray = new JSONArray();
|
||||
for (Group group : groups)
|
||||
jsonArray.put(group.toJson());
|
||||
return jsonArray;
|
||||
}
|
||||
|
||||
}
|
|
@ -1,100 +0,0 @@
|
|||
/*
|
||||
* This file is part of snapcast
|
||||
* Copyright (C) 2014-2017 Johannes Pohl
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package de.badaix.snapcast.control.json;
|
||||
|
||||
import org.json.JSONException;
|
||||
import org.json.JSONObject;
|
||||
|
||||
/**
|
||||
* Created by johannes on 06.01.16.
|
||||
*/
|
||||
public class Snapcast implements JsonSerialisable {
|
||||
String name = "";
|
||||
String version = "";
|
||||
int protocolVersion = 1;
|
||||
|
||||
public Snapcast() {
|
||||
}
|
||||
|
||||
public Snapcast(JSONObject json) {
|
||||
fromJson(json);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void fromJson(JSONObject json) {
|
||||
try {
|
||||
name = json.getString("name");
|
||||
version = json.getString("version");
|
||||
protocolVersion = json.getInt("protocolVersion");
|
||||
} catch (JSONException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public JSONObject toJson() {
|
||||
JSONObject json = new JSONObject();
|
||||
try {
|
||||
json.put("name", name);
|
||||
json.put("version", version);
|
||||
json.put("protocolVersion", protocolVersion);
|
||||
} catch (JSONException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return json;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public String getVersion() {
|
||||
return version;
|
||||
}
|
||||
|
||||
public int getProtocolVersion() {
|
||||
return protocolVersion;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return toJson().toString();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
if (this == o) return true;
|
||||
if (o == null || getClass() != o.getClass()) return false;
|
||||
|
||||
Snapcast that = (Snapcast) o;
|
||||
|
||||
if (name != null ? !name.equals(that.name) : that.name != null) return false;
|
||||
if (version != null ? !version.equals(that.version) : that.version != null) return false;
|
||||
return (protocolVersion == that.protocolVersion);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
int result = name != null ? name.hashCode() : 0;
|
||||
result = 31 * result + (version != null ? version.hashCode() : 0);
|
||||
result = 31 * result + protocolVersion;
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
|
@ -1,36 +0,0 @@
|
|||
/*
|
||||
* This file is part of snapcast
|
||||
* Copyright (C) 2014-2017 Johannes Pohl
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package de.badaix.snapcast.control.json;
|
||||
|
||||
import org.json.JSONObject;
|
||||
|
||||
/**
|
||||
* Created by johannes on 06.01.16.
|
||||
*/
|
||||
public class Snapclient extends Snapcast {
|
||||
|
||||
public Snapclient() {
|
||||
super();
|
||||
}
|
||||
|
||||
public Snapclient(JSONObject json) {
|
||||
super(json);
|
||||
}
|
||||
}
|
||||
|
|
@ -1,81 +0,0 @@
|
|||
/*
|
||||
* This file is part of snapcast
|
||||
* Copyright (C) 2014-2017 Johannes Pohl
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package de.badaix.snapcast.control.json;
|
||||
|
||||
import org.json.JSONException;
|
||||
import org.json.JSONObject;
|
||||
|
||||
/**
|
||||
* Created by johannes on 06.01.16.
|
||||
*/
|
||||
public class Snapserver extends Snapcast {
|
||||
int controlProtocolVersion = 1;
|
||||
|
||||
public Snapserver() {
|
||||
super();
|
||||
}
|
||||
|
||||
public Snapserver(JSONObject json) {
|
||||
super(json);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void fromJson(JSONObject json) {
|
||||
try {
|
||||
super.fromJson(json);
|
||||
controlProtocolVersion = json.getInt("controlProtocolVersion");
|
||||
} catch (JSONException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public JSONObject toJson() {
|
||||
JSONObject json = super.toJson();
|
||||
try {
|
||||
json.put("controlProtocolVersion", controlProtocolVersion);
|
||||
} catch (JSONException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return json;
|
||||
}
|
||||
|
||||
public int getControlProtocolVersion() {
|
||||
return controlProtocolVersion;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
if (this == o) return true;
|
||||
if (o == null || getClass() != o.getClass()) return false;
|
||||
|
||||
Snapserver that = (Snapserver) o;
|
||||
|
||||
if (controlProtocolVersion != that.controlProtocolVersion) return false;
|
||||
return super.equals(o);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
int result = super.hashCode();
|
||||
result = 31 * result + controlProtocolVersion;
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
|
@ -1,142 +0,0 @@
|
|||
/*
|
||||
* This file is part of snapcast
|
||||
* Copyright (C) 2014-2017 Johannes Pohl
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package de.badaix.snapcast.control.json;
|
||||
|
||||
import org.json.JSONException;
|
||||
import org.json.JSONObject;
|
||||
|
||||
/**
|
||||
* Created by johannes on 06.01.16.
|
||||
*/
|
||||
public class Stream implements JsonSerialisable {
|
||||
private StreamUri uri;
|
||||
private String id;
|
||||
private Status status;
|
||||
|
||||
public Stream(JSONObject json) {
|
||||
fromJson(json);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void fromJson(JSONObject json) {
|
||||
try {
|
||||
if (json.has("uri") && (json.get("uri") instanceof JSONObject)) {
|
||||
uri = new StreamUri(json.getJSONObject("uri"));
|
||||
id = json.getString("id");
|
||||
status = Status.fromString(json.getString("status"));
|
||||
} else {
|
||||
uri = new StreamUri(json);
|
||||
id = json.getString("id");
|
||||
status = Status.unknown;
|
||||
}
|
||||
} catch (JSONException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public JSONObject toJson() {
|
||||
JSONObject json = new JSONObject();
|
||||
try {
|
||||
json.put("uri", uri.toJson());
|
||||
json.put("id", id);
|
||||
json.put("status", status);
|
||||
} catch (JSONException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return json;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
if (this == o) return true;
|
||||
if (o == null || getClass() != o.getClass()) return false;
|
||||
|
||||
Stream stream = (Stream) o;
|
||||
|
||||
if (uri != null ? !uri.equals(stream.uri) : stream.uri != null) return false;
|
||||
if (id != null ? !id.equals(stream.id) : stream.id != null) return false;
|
||||
return !(status != null ? !status.equals(stream.status) : stream.status != null);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
int result = uri != null ? uri.hashCode() : 0;
|
||||
result = 31 * result + (id != null ? id.hashCode() : 0);
|
||||
result = 31 * result + (status != null ? status.hashCode() : 0);
|
||||
return result;
|
||||
}
|
||||
|
||||
public StreamUri getUri() {
|
||||
return uri;
|
||||
}
|
||||
|
||||
public void setUri(StreamUri uri) {
|
||||
this.uri = uri;
|
||||
}
|
||||
|
||||
public String getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public void setId(String id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public Status getStatus() {
|
||||
return status;
|
||||
}
|
||||
|
||||
public void setStatus(Status status) {
|
||||
this.status = status;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return uri.getName();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return toJson().toString();
|
||||
}
|
||||
|
||||
public enum Status {
|
||||
unknown("unknown"),
|
||||
idle("idle"),
|
||||
playing("playing"),
|
||||
disabled("disabled");
|
||||
|
||||
private String status;
|
||||
|
||||
Status(String status) {
|
||||
this.status = status;
|
||||
}
|
||||
|
||||
public static Status fromString(String status) {
|
||||
if (status != null) {
|
||||
for (Status s : Status.values()) {
|
||||
if (status.equalsIgnoreCase(s.status)) {
|
||||
return s;
|
||||
}
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,167 +0,0 @@
|
|||
/*
|
||||
* This file is part of snapcast
|
||||
* Copyright (C) 2014-2017 Johannes Pohl
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package de.badaix.snapcast.control.json;
|
||||
|
||||
import org.json.JSONException;
|
||||
import org.json.JSONObject;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* Created by johannes on 06.01.16.
|
||||
*/
|
||||
public class StreamUri implements JsonSerialisable {
|
||||
private String raw;
|
||||
private String scheme;
|
||||
private String host;
|
||||
private String path;
|
||||
private String fragment;
|
||||
private HashMap<String, String> query;
|
||||
|
||||
public StreamUri(JSONObject json) {
|
||||
fromJson(json);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void fromJson(JSONObject json) {
|
||||
try {
|
||||
if (json.has("raw"))
|
||||
raw = json.getString("raw");
|
||||
else if (json.has("uri"))
|
||||
raw = json.getString("uri");
|
||||
scheme = json.getString("scheme");
|
||||
host = json.getString("host");
|
||||
path = json.getString("path");
|
||||
fragment = json.getString("fragment");
|
||||
query = new HashMap<>();
|
||||
JSONObject jQuery = json.getJSONObject("query");
|
||||
for (int i = 0; i < jQuery.names().length(); i++)
|
||||
query.put(jQuery.names().getString(i), jQuery.getString(jQuery.names().getString(i)));
|
||||
} catch (JSONException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public JSONObject toJson() {
|
||||
JSONObject json = new JSONObject();
|
||||
try {
|
||||
json.put("raw", raw);
|
||||
json.put("scheme", scheme);
|
||||
json.put("host", host);
|
||||
json.put("path", path);
|
||||
json.put("fragment", fragment);
|
||||
JSONObject jQuery = new JSONObject();
|
||||
for (Map.Entry<String, String> entry : query.entrySet())
|
||||
jQuery.put(entry.getKey(), entry.getValue());
|
||||
json.put("query", jQuery);
|
||||
} catch (JSONException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return json;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
if (this == o) return true;
|
||||
if (o == null || getClass() != o.getClass()) return false;
|
||||
|
||||
StreamUri stream = (StreamUri) o;
|
||||
|
||||
if (raw != null ? !raw.equals(stream.raw) : stream.raw != null) return false;
|
||||
if (scheme != null ? !scheme.equals(stream.scheme) : stream.scheme != null) return false;
|
||||
if (host != null ? !host.equals(stream.host) : stream.host != null) return false;
|
||||
if (path != null ? !path.equals(stream.path) : stream.path != null) return false;
|
||||
if (fragment != null ? !fragment.equals(stream.fragment) : stream.fragment != null)
|
||||
return false;
|
||||
return !(query != null ? !query.equals(stream.query) : stream.query != null);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
int result = raw != null ? raw.hashCode() : 0;
|
||||
result = 31 * result + (scheme != null ? scheme.hashCode() : 0);
|
||||
result = 31 * result + (host != null ? host.hashCode() : 0);
|
||||
result = 31 * result + (path != null ? path.hashCode() : 0);
|
||||
result = 31 * result + (fragment != null ? fragment.hashCode() : 0);
|
||||
result = 31 * result + (query != null ? query.hashCode() : 0);
|
||||
return result;
|
||||
}
|
||||
|
||||
public String getRaw() {
|
||||
return raw;
|
||||
}
|
||||
|
||||
public void setUri(String uri) {
|
||||
this.raw = raw;
|
||||
}
|
||||
|
||||
public String getScheme() {
|
||||
return scheme;
|
||||
}
|
||||
|
||||
public void setScheme(String scheme) {
|
||||
this.scheme = scheme;
|
||||
}
|
||||
|
||||
public String getHost() {
|
||||
return host;
|
||||
}
|
||||
|
||||
public void setHost(String host) {
|
||||
this.host = host;
|
||||
}
|
||||
|
||||
public String getPath() {
|
||||
return path;
|
||||
}
|
||||
|
||||
public void setPath(String path) {
|
||||
this.path = path;
|
||||
}
|
||||
|
||||
public String getFragment() {
|
||||
return fragment;
|
||||
}
|
||||
|
||||
public void setFragment(String fragment) {
|
||||
this.fragment = fragment;
|
||||
}
|
||||
|
||||
public HashMap<String, String> getQuery() {
|
||||
return query;
|
||||
}
|
||||
|
||||
public void setQuery(HashMap<String, String> query) {
|
||||
this.query = query;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
if (query.containsKey("name"))
|
||||
return query.get("name");
|
||||
else
|
||||
return "";
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return toJson().toString();
|
||||
}
|
||||
}
|
|
@ -1,105 +0,0 @@
|
|||
/*
|
||||
* This file is part of snapcast
|
||||
* Copyright (C) 2014-2017 Johannes Pohl
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package de.badaix.snapcast.control.json;
|
||||
|
||||
import org.json.JSONException;
|
||||
import org.json.JSONObject;
|
||||
|
||||
/**
|
||||
* Created by johannes on 06.01.16.
|
||||
*/
|
||||
public class Time_t implements JsonSerialisable {
|
||||
private long sec = 0;
|
||||
private long usec = 0;
|
||||
|
||||
public Time_t() {
|
||||
|
||||
}
|
||||
|
||||
public Time_t(JSONObject json) {
|
||||
fromJson(json);
|
||||
}
|
||||
|
||||
public Time_t(long sec, long usec) {
|
||||
this.sec = sec;
|
||||
this.usec = usec;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void fromJson(JSONObject json) {
|
||||
try {
|
||||
sec = json.getLong("sec");
|
||||
usec = json.getLong("usec");
|
||||
} catch (JSONException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public JSONObject toJson() {
|
||||
JSONObject json = new JSONObject();
|
||||
try {
|
||||
json.put("sec", sec);
|
||||
json.put("usec", usec);
|
||||
} catch (JSONException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return json;
|
||||
}
|
||||
|
||||
public long getSec() {
|
||||
return sec;
|
||||
}
|
||||
|
||||
public void setSec(long sec) {
|
||||
this.sec = sec;
|
||||
}
|
||||
|
||||
public long getUsec() {
|
||||
return usec;
|
||||
}
|
||||
|
||||
public void setUsec(long usec) {
|
||||
this.usec = usec;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return toJson().toString();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
if (this == o) return true;
|
||||
if (o == null || getClass() != o.getClass()) return false;
|
||||
|
||||
Time_t time_t = (Time_t) o;
|
||||
|
||||
if (sec != time_t.sec) return false;
|
||||
return usec == time_t.usec;
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
int result = (int) sec;
|
||||
result = (int) (31 * result + usec);
|
||||
return result;
|
||||
}
|
||||
}
|
|
@ -1,105 +0,0 @@
|
|||
/*
|
||||
* This file is part of snapcast
|
||||
* Copyright (C) 2014-2017 Johannes Pohl
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package de.badaix.snapcast.control.json;
|
||||
|
||||
import org.json.JSONException;
|
||||
import org.json.JSONObject;
|
||||
|
||||
/**
|
||||
* Created by johannes on 06.01.16.
|
||||
*/
|
||||
public class Volume implements JsonSerialisable {
|
||||
private boolean muted = false;
|
||||
private int percent = 100;
|
||||
|
||||
public Volume(JSONObject json) {
|
||||
fromJson(json);
|
||||
}
|
||||
|
||||
public Volume() {
|
||||
|
||||
}
|
||||
|
||||
public Volume(int percent, boolean muted) {
|
||||
this.percent = percent;
|
||||
this.muted = muted;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void fromJson(JSONObject json) {
|
||||
try {
|
||||
percent = json.getInt("percent");
|
||||
muted = json.getBoolean("muted");
|
||||
} catch (JSONException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public JSONObject toJson() {
|
||||
JSONObject json = new JSONObject();
|
||||
try {
|
||||
json.put("percent", percent);
|
||||
json.put("muted", muted);
|
||||
} catch (JSONException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return json;
|
||||
}
|
||||
|
||||
public int getPercent() {
|
||||
return percent;
|
||||
}
|
||||
|
||||
public void setPercent(int percent) {
|
||||
this.percent = percent;
|
||||
}
|
||||
|
||||
public boolean isMuted() {
|
||||
return muted;
|
||||
}
|
||||
|
||||
public void setMuted(boolean muted) {
|
||||
this.muted = muted;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return toJson().toString();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
if (this == o) return true;
|
||||
if (o == null || getClass() != o.getClass()) return false;
|
||||
|
||||
Volume volume = (Volume) o;
|
||||
|
||||
if (muted != volume.muted) return false;
|
||||
return percent == volume.percent;
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
int result = (muted ? 1 : 0);
|
||||
result = 31 * result + percent;
|
||||
return result;
|
||||
}
|
||||
}
|
|
@ -1,114 +0,0 @@
|
|||
/*
|
||||
* This file is part of snapcast
|
||||
* Copyright (C) 2014-2017 Johannes Pohl
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package de.badaix.snapcast.utils;
|
||||
|
||||
/*
|
||||
* Copyright (C) 2012 The CyanogenMod Project
|
||||
*
|
||||
* * Licensed under the GNU GPLv2 license
|
||||
*
|
||||
* The text of the license can be found in the LICENSE file
|
||||
* or at https://www.gnu.org/licenses/gpl-2.0.txt
|
||||
*/
|
||||
|
||||
import android.text.TextUtils;
|
||||
import android.util.Log;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileInputStream;
|
||||
import java.io.FileNotFoundException;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.math.BigInteger;
|
||||
import java.security.MessageDigest;
|
||||
import java.security.NoSuchAlgorithmException;
|
||||
|
||||
public class MD5 {
|
||||
private static final String TAG = "MD5";
|
||||
|
||||
public static boolean checkMD5(String md5, File updateFile) {
|
||||
if (TextUtils.isEmpty(md5) || updateFile == null) {
|
||||
Log.e(TAG, "MD5 string empty or updateFile null");
|
||||
return false;
|
||||
}
|
||||
|
||||
String calculatedDigest = calculateMD5(updateFile);
|
||||
if (calculatedDigest == null) {
|
||||
Log.e(TAG, "calculatedDigest null");
|
||||
return false;
|
||||
}
|
||||
|
||||
Log.v(TAG, "Calculated digest: " + calculatedDigest);
|
||||
Log.v(TAG, "Provided digest: " + md5);
|
||||
|
||||
return calculatedDigest.equalsIgnoreCase(md5);
|
||||
}
|
||||
|
||||
public static String calculateMD5(File updateFile) {
|
||||
InputStream is;
|
||||
try {
|
||||
is = new FileInputStream(updateFile);
|
||||
} catch (FileNotFoundException e) {
|
||||
Log.e(TAG, "Exception while getting FileInputStream", e);
|
||||
return null;
|
||||
}
|
||||
try {
|
||||
return calculateMD5(is);
|
||||
} finally {
|
||||
try {
|
||||
is.close();
|
||||
} catch (IOException e) {
|
||||
Log.e(TAG, "Exception on closing MD5 input stream", e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static String calculateMD5(InputStream is) {
|
||||
MessageDigest digest;
|
||||
try {
|
||||
digest = MessageDigest.getInstance("MD5");
|
||||
} catch (NoSuchAlgorithmException e) {
|
||||
Log.e(TAG, "Exception while getting digest", e);
|
||||
return null;
|
||||
}
|
||||
|
||||
byte[] buffer = new byte[8192];
|
||||
int read;
|
||||
try {
|
||||
while ((read = is.read(buffer)) > 0) {
|
||||
digest.update(buffer, 0, read);
|
||||
}
|
||||
byte[] md5sum = digest.digest();
|
||||
BigInteger bigInt = new BigInteger(1, md5sum);
|
||||
String output = bigInt.toString(16);
|
||||
// Fill to 32 chars
|
||||
output = String.format("%32s", output).replace(' ', '0');
|
||||
return output;
|
||||
} catch (IOException e) {
|
||||
throw new RuntimeException("Unable to process file for MD5", e);
|
||||
} finally {
|
||||
try {
|
||||
is.reset();
|
||||
} catch (IOException e) {
|
||||
Log.e(TAG, "Exception on closing MD5 input stream", e);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -1,144 +0,0 @@
|
|||
/*
|
||||
* This file is part of snapcast
|
||||
* Copyright (C) 2014-2017 Johannes Pohl
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package de.badaix.snapcast.utils;
|
||||
|
||||
/**
|
||||
* Created by johannes on 19.01.16.
|
||||
*/
|
||||
|
||||
import android.annotation.TargetApi;
|
||||
import android.content.Context;
|
||||
import android.net.nsd.NsdManager;
|
||||
import android.net.nsd.NsdServiceInfo;
|
||||
import android.os.Build;
|
||||
import android.util.Log;
|
||||
|
||||
import java.net.InetAddress;
|
||||
|
||||
@TargetApi(Build.VERSION_CODES.JELLY_BEAN)
|
||||
public class NsdHelper {
|
||||
|
||||
private static final String TAG = "NsdHelper";
|
||||
private static NsdHelper mInstance;
|
||||
private String serviceName;
|
||||
private String serviceType;
|
||||
// private static final String NSD_SERVICE_TYPE = "_http._tcp.";
|
||||
private int mPort;
|
||||
private InetAddress mHost;
|
||||
private NsdManager mNsdManager;
|
||||
private android.net.nsd.NsdManager.DiscoveryListener mDiscoveryListener = null;
|
||||
private android.net.nsd.NsdManager.ResolveListener mResolveListener = null;
|
||||
private Context mContext;
|
||||
private NsdHelperListener listener = null;
|
||||
|
||||
private NsdHelper(Context context) {
|
||||
mContext = context;
|
||||
}
|
||||
|
||||
public static NsdHelper getInstance(Context context) {
|
||||
if (mInstance == null) {
|
||||
mInstance = new NsdHelper(context);
|
||||
} else {
|
||||
mInstance.mContext = context;
|
||||
}
|
||||
return mInstance;
|
||||
}
|
||||
|
||||
public void startListening(String serviceType, String serviceName, NsdHelperListener listener) {
|
||||
stopListening();
|
||||
this.listener = listener;
|
||||
this.serviceName = serviceName;
|
||||
this.serviceType = serviceType;
|
||||
initializeResolveListener();
|
||||
initializeDiscoveryListener();
|
||||
mNsdManager = (NsdManager) mContext.getSystemService(Context.NSD_SERVICE);
|
||||
mNsdManager.discoverServices(serviceType, NsdManager.PROTOCOL_DNS_SD, mDiscoveryListener);
|
||||
// mNsdManager.discoverServices("_snapcast-jsonrpc._tcp.", NsdManager.PROTOCOL_DNS_SD, mDiscoveryListener);
|
||||
}
|
||||
|
||||
public void stopListening() {
|
||||
if (mDiscoveryListener != null) {
|
||||
try {
|
||||
mNsdManager.stopServiceDiscovery(mDiscoveryListener);
|
||||
} finally {
|
||||
}
|
||||
mDiscoveryListener = null;
|
||||
}
|
||||
}
|
||||
|
||||
private void initializeResolveListener() {
|
||||
mResolveListener = new NsdManager.ResolveListener() {
|
||||
@Override
|
||||
public void onResolveFailed(NsdServiceInfo serviceInfo, int errorCode) {
|
||||
Log.d(TAG, "Resolve failed");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onServiceResolved(NsdServiceInfo serviceInfo) {
|
||||
NsdServiceInfo info = serviceInfo;
|
||||
// sometimes it returns an IPv6 address...
|
||||
if (!info.getHost().getCanonicalHostName().contains(":"))
|
||||
listener.onResolved(NsdHelper.this, serviceInfo);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
private void initializeDiscoveryListener() {
|
||||
mDiscoveryListener = new NsdManager.DiscoveryListener() {
|
||||
@Override
|
||||
public void onStartDiscoveryFailed(String serviceType, int errorCode) {
|
||||
Log.d(TAG, "Discovery failed");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onStopDiscoveryFailed(String serviceType, int errorCode) {
|
||||
Log.d(TAG, "Stopping discovery failed");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDiscoveryStarted(String serviceType) {
|
||||
Log.d(TAG, "Discovery started");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDiscoveryStopped(String serviceType) {
|
||||
Log.d(TAG, "Discovery stopped");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onServiceFound(NsdServiceInfo serviceInfo) {
|
||||
NsdServiceInfo info = serviceInfo;
|
||||
Log.d(TAG, "Service found: " + info.getServiceName());
|
||||
if (info.getServiceName().equals(serviceName))
|
||||
mNsdManager.resolveService(info, mResolveListener);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onServiceLost(NsdServiceInfo serviceInfo) {
|
||||
NsdServiceInfo info = serviceInfo;
|
||||
Log.d(TAG, "Service lost: " + info.getServiceName());
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
public interface NsdHelperListener {
|
||||
void onResolved(NsdHelper nsdHelper, NsdServiceInfo serviceInfo);
|
||||
}
|
||||
}
|
||||
|
|
@ -1,135 +0,0 @@
|
|||
/*
|
||||
* This file is part of snapcast
|
||||
* Copyright (C) 2014-2017 Johannes Pohl
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package de.badaix.snapcast.utils;
|
||||
|
||||
import android.content.Context;
|
||||
import android.content.SharedPreferences;
|
||||
import android.content.res.Resources;
|
||||
import android.preference.PreferenceManager;
|
||||
|
||||
/**
|
||||
* Created by johannes on 21.02.16.
|
||||
*/
|
||||
public class Settings {
|
||||
private static Settings instance = null;
|
||||
private Context ctx = null;
|
||||
|
||||
public static Settings getInstance(Context context) {
|
||||
if (instance == null) {
|
||||
instance = new Settings();
|
||||
}
|
||||
if (context != null)
|
||||
instance.ctx = context.getApplicationContext();
|
||||
|
||||
return instance;
|
||||
}
|
||||
|
||||
public Context getContext() {
|
||||
return ctx;
|
||||
}
|
||||
|
||||
public Resources getResources() {
|
||||
return ctx.getResources();
|
||||
}
|
||||
|
||||
public SharedPreferences getPrefs() {
|
||||
return PreferenceManager.getDefaultSharedPreferences(ctx);
|
||||
}
|
||||
|
||||
public Settings put(String key, String value) {
|
||||
SharedPreferences.Editor editor = getPrefs().edit();
|
||||
editor.putString(key, value);
|
||||
editor.apply();
|
||||
return this;
|
||||
}
|
||||
|
||||
public Settings put(String key, boolean value) {
|
||||
SharedPreferences.Editor editor = getPrefs().edit();
|
||||
editor.putBoolean(key, value);
|
||||
editor.apply();
|
||||
return this;
|
||||
}
|
||||
|
||||
public Settings put(String key, float value) {
|
||||
SharedPreferences.Editor editor = getPrefs().edit();
|
||||
editor.putFloat(key, value);
|
||||
editor.apply();
|
||||
return this;
|
||||
}
|
||||
|
||||
public Settings put(String key, int value) {
|
||||
SharedPreferences.Editor editor = getPrefs().edit();
|
||||
editor.putInt(key, value);
|
||||
editor.apply();
|
||||
return this;
|
||||
}
|
||||
|
||||
public Settings put(String key, long value) {
|
||||
SharedPreferences.Editor editor = getPrefs().edit();
|
||||
editor.putLong(key, value);
|
||||
editor.apply();
|
||||
return this;
|
||||
}
|
||||
|
||||
public String getString(String key, String defaultValue) {
|
||||
return getPrefs().getString(key, defaultValue);
|
||||
}
|
||||
|
||||
public boolean getBoolean(String key, boolean defaultValue) {
|
||||
return getPrefs().getBoolean(key, defaultValue);
|
||||
}
|
||||
|
||||
public float getFloat(String key, float defaultValue) {
|
||||
return getPrefs().getFloat(key, defaultValue);
|
||||
}
|
||||
|
||||
public int getInt(String key, int defaultValue) {
|
||||
return getPrefs().getInt(key, defaultValue);
|
||||
}
|
||||
|
||||
public long getLong(String key, long defaultValue) {
|
||||
return getPrefs().getLong(key, defaultValue);
|
||||
}
|
||||
|
||||
public String getHost() {
|
||||
return getString("host", "");
|
||||
}
|
||||
|
||||
public int getStreamPort() {
|
||||
return getInt("streamPort", 1704);
|
||||
}
|
||||
|
||||
public int getControlPort() {
|
||||
return getInt("controlPort", getStreamPort() + 1);
|
||||
}
|
||||
|
||||
public boolean isAutostart() {
|
||||
return getBoolean("autoStart", false);
|
||||
}
|
||||
|
||||
public void setAutostart(boolean autoStart) {
|
||||
put("autoStart", autoStart);
|
||||
}
|
||||
|
||||
public void setHost(String host, int streamPort, int controlPort) {
|
||||
put("host", host);
|
||||
put("streamPort", streamPort);
|
||||
put("controlPort", controlPort);
|
||||
}
|
||||
}
|
|
@ -1,138 +0,0 @@
|
|||
/*
|
||||
* This file is part of snapcast
|
||||
* Copyright (C) 2014-2017 Johannes Pohl
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package de.badaix.snapcast.utils;
|
||||
|
||||
import android.content.Context;
|
||||
import android.content.res.AssetManager;
|
||||
import android.util.Log;
|
||||
|
||||
import java.io.BufferedReader;
|
||||
import java.io.File;
|
||||
import java.io.FileOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.io.InputStreamReader;
|
||||
import java.io.OutputStream;
|
||||
|
||||
/**
|
||||
* Created by johannes on 16.01.16.
|
||||
*/
|
||||
public class Setup {
|
||||
|
||||
private static final String TAG = "Setup";
|
||||
|
||||
public static String getProp(String prop, String def) {
|
||||
Process process = null;
|
||||
try {
|
||||
process = new ProcessBuilder()
|
||||
.command("/system/bin/getprop", prop)
|
||||
.redirectErrorStream(true)
|
||||
.start();
|
||||
|
||||
BufferedReader bufferedReader = new BufferedReader(
|
||||
new InputStreamReader(process.getInputStream()));
|
||||
String line;
|
||||
if ((line = bufferedReader.readLine()) != null) {
|
||||
return line;
|
||||
}
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
return def;
|
||||
}
|
||||
|
||||
public static boolean copyBinAsset(Context context, String sourceFilename, String destFilename) {
|
||||
if (copyAsset(context, "bin/" + getProp("ro.product.cpu.abi", "armeabi") + "/" + sourceFilename, destFilename))
|
||||
return true;
|
||||
else if (copyAsset(context, "bin/" + getProp("ro.product.cpu.abi2", "armeabi") + "/" + sourceFilename, destFilename))
|
||||
return true;
|
||||
else if (copyAsset(context, "bin/armeabi/" + sourceFilename, destFilename))
|
||||
return true;
|
||||
return false;
|
||||
}
|
||||
|
||||
public static boolean copyAsset(Context context, String sourceFilename, String destFilename) {
|
||||
AssetManager assetManager = context.getAssets();
|
||||
|
||||
InputStream in = null;
|
||||
OutputStream out = null;
|
||||
try {
|
||||
in = assetManager.open(sourceFilename);
|
||||
String md5 = MD5.calculateMD5(in);
|
||||
File outFile = new File(context.getFilesDir(), destFilename);
|
||||
Log.d(TAG, "Asset: " + sourceFilename + " => " + outFile.getAbsolutePath() + ", md5: " + md5);
|
||||
String hashKey = "asset_" + sourceFilename;
|
||||
if (outFile.exists() && md5.equals(Settings.getInstance(context).getString(hashKey, "")))
|
||||
return true;
|
||||
Log.d(TAG, "Copying " + sourceFilename + " => " + outFile.getAbsolutePath());
|
||||
out = new FileOutputStream(outFile);
|
||||
copyFile(in, out);
|
||||
Runtime.getRuntime().exec("chmod 755 " + outFile.getAbsolutePath()).waitFor();
|
||||
Settings.getInstance(context).put(hashKey, md5);
|
||||
return true;
|
||||
} catch (Exception e) {
|
||||
Log.e(TAG, "Failed to copy asset file: " + sourceFilename, e);
|
||||
} finally {
|
||||
if (in != null) {
|
||||
try {
|
||||
in.close();
|
||||
} catch (IOException e) {
|
||||
// NOOP
|
||||
}
|
||||
}
|
||||
if (out != null) {
|
||||
try {
|
||||
out.close();
|
||||
} catch (IOException e) {
|
||||
// NOOP
|
||||
}
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public static void copyAssets(Context context, String sourceDir, String destDir) {
|
||||
AssetManager assetManager = context.getAssets();
|
||||
String[] files = null;
|
||||
try {
|
||||
files = assetManager.list(sourceDir);
|
||||
if (files == null)
|
||||
return;
|
||||
} catch (IOException e) {
|
||||
Log.e(TAG, "Failed to get asset file list.", e);
|
||||
}
|
||||
|
||||
for (String file : files) {
|
||||
String sourceFile = sourceDir + "/" + file;
|
||||
String destFile = destDir + "/" + file;
|
||||
copyAsset(context, sourceFile, destFile);
|
||||
}
|
||||
}
|
||||
|
||||
public static void copyFile(InputStream in, OutputStream out) throws IOException {
|
||||
byte[] buffer = new byte[1024];
|
||||
int read;
|
||||
while ((read = in.read(buffer)) != -1) {
|
||||
out.write(buffer, 0, read);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
Before Width: | Height: | Size: 599 B |
Before Width: | Height: | Size: 1.1 KiB |
Before Width: | Height: | Size: 399 B |
Before Width: | Height: | Size: 932 B |
Before Width: | Height: | Size: 453 B |
Before Width: | Height: | Size: 460 B |
Before Width: | Height: | Size: 1.3 KiB |
Before Width: | Height: | Size: 540 B |
Before Width: | Height: | Size: 897 B |
Before Width: | Height: | Size: 348 B |
Before Width: | Height: | Size: 591 B |
Before Width: | Height: | Size: 322 B |
Before Width: | Height: | Size: 326 B |
Before Width: | Height: | Size: 773 B |
Before Width: | Height: | Size: 685 B |
Before Width: | Height: | Size: 1.6 KiB |
Before Width: | Height: | Size: 493 B |
Before Width: | Height: | Size: 1.2 KiB |
Before Width: | Height: | Size: 557 B |
Before Width: | Height: | Size: 562 B |
Before Width: | Height: | Size: 1.7 KiB |
Before Width: | Height: | Size: 611 B |
Before Width: | Height: | Size: 1.2 KiB |
Before Width: | Height: | Size: 441 B |
Before Width: | Height: | Size: 1.8 KiB |
Before Width: | Height: | Size: 827 B |
Before Width: | Height: | Size: 843 B |
Before Width: | Height: | Size: 2.7 KiB |
Before Width: | Height: | Size: 2.5 KiB |
Before Width: | Height: | Size: 1 KiB |
Before Width: | Height: | Size: 1 KiB |
Before Width: | Height: | Size: 3.8 KiB |
|
@ -1,28 +0,0 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<!--
|
||||
~ This file is part of snapcast
|
||||
~ Copyright (C) 2014-2017 Johannes Pohl
|
||||
~
|
||||
~ This program is free software: you can redistribute it and/or modify
|
||||
~ it under the terms of the GNU General Public License as published by
|
||||
~ the Free Software Foundation, either version 3 of the License, or
|
||||
~ (at your option) any later version.
|
||||
~
|
||||
~ This program is distributed in the hope that it will be useful,
|
||||
~ but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
~ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
~ GNU General Public License for more details.
|
||||
~
|
||||
~ You should have received a copy of the GNU General Public License
|
||||
~ along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
-->
|
||||
<vector xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:width="24dp"
|
||||
android:height="24dp"
|
||||
android:viewportWidth="24.0"
|
||||
android:viewportHeight="24.0"
|
||||
android:tint="?attr/colorControlNormal">
|
||||
<path
|
||||
android:pathData="M12,8c1.1,0 2,-0.9 2,-2s-0.9,-2 -2,-2c-1.1,0 -2,0.9 -2,2S10.9,8 12,8zM12,10c-1.1,0 -2,0.9 -2,2s0.9,2 2,2c1.1,0 2,-0.9 2,-2S13.1,10 12,10zM12,16c-1.1,0 -2,0.9 -2,2s0.9,2 2,2c1.1,0 2,-0.9 2,-2S13.1,16 12,16z"
|
||||
android:fillColor="@android:color/white"/>
|
||||
</vector>
|