Code Monkey home page Code Monkey logo

scplayer's Introduction

SCPlayer - Spotify Connect Player

Open source client of Spotify Connect closed library developed in Java

I decided to make a Java version because i needed the player to run without any privileged or any additional installation.

This version is working with Raspberry Pi 2 with the hard float version of the spotify's library

There is a version to run in Raspberry Pi 1 here, but it only works in a soft float system (you will have to install Raspbian armel or emulate with chroot, docker, etc...). This version will only be updated after a while the main version.

It's possible that it will be run other devices if you use the right version of spotify's library.

If you managed to run on others devices, or need help to, let me know.

Quick run / I just want to use

  1. Download Java, link here
  2. Get apropriate version of spotify lib, you can find all versions on this github, to run in Raspberry Pi 2 is this one
  3. Get your spotify key, here, download the binary version
  4. Get SCPlayer jar, here
  5. Put all on the same folder
  6. Run using the command /path/to/java -jar SCPlayer.jar
  7. From a browser access: http://IP:4000 and login with your login clicking on the right top conner

Detailed Usage

Java options -D<option>=<value>

  • player.name - Set the player name, will appears on all your connect devices (Default will be SCPlayer)
  • username - Set username
  • password - Set password
  • remember.me - Save your credentials for the next start (true/false), defaults to true
  • standalone - Runs without the web version (true/false)
  • debug - Set debug level - 0 > WARN, 1 > INFO, 2 > DEBUG, 3 > TRACE
  • app.key - Path to your spotify_appkey.key
  • list.mixers - List the available mixers for use
  • mixer - Set the mixer, you can use either the name or index provided by list.mixers
  • bitrate - Set the bitrate (90/160/320)
  • zeroconf.provider - Zeroconf authentication provider (library/opensource), defaults to opensource
  • zeroconf.service - Zeroconf authentication service (avahi/jmdns), defaults to avahi, if not found uses JmDNS (May not work on Windows clients)

Example: ./jdk1.8.0_60/bin/java -Dplayer.name=Kitchen -Dmixer=0 -Dapp.key=/home/pi/spotify_appkey.key -jar SCPlayer.jar

Use as a Service

Details here

Troubleshooting

If you are running on Openelec like I am, you have to run this command to enable alsa drivers
from ssh type echo snd_bcm2835 >> /storage/.config/modules-load.d/audio.conf
after version 6 you may also have to add dtparam=audio=on to config.txt
and reboot

If you are running on OSMC you have to run this command to enable alsa drivers
for older versions from ssh type sudo modprobe snd_bcm2835 , no need to reboot
for newer versions add this line dtparam=audio=on to /boot/config.txt

Disclaimer

Using this code to connect to Spotify's API is probably forbidden by them, and might result in your application key getting banned. Use at you own risk

scplayer's People

Contributors

crsmoro avatar leanderk avatar vit3k avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

scplayer's Issues

Error with USB DAC

Hi,

I'm using a SMSL Q5 as USB DAC but when I'm using it this is a error log I have:

2015-11-23 22:14:54 ERROR AudioPlayer:67 - onActive error
javax.sound.sampled.LineUnavailableException: line with format PCM_SIGNED 44100.0 Hz, 16 bit, stereo, 4 bytes/frame, little-endian not supported.
    at com.sun.media.sound.DirectAudioDevice$DirectDL.implOpen(DirectAudioDevice.java:513)
    at com.sun.media.sound.AbstractDataLine.open(AbstractDataLine.java:121)
    at com.sun.media.sound.AbstractDataLine.open(AbstractDataLine.java:153)
    at com.shuffle.scplayer.core.AudioPlayer.onActive(AudioPlayer.java:62)
    at com.shuffle.scplayer.core.AudioPlayer.onPlay(AudioPlayer.java:81)
    at com.shuffle.scplayer.core.SpotifyConnectPlayerImpl$5.apply(SpotifyConnectPlayerImpl.java:190)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:497)
    at com.sun.jna.CallbackReference$DefaultCallbackProxy.invokeCallback(CallbackReference.java:485)
    at com.sun.jna.CallbackReference$DefaultCallbackProxy.callback(CallbackReference.java:515)
    at com.sun.jna.Native.invokeInt(Native Method)
    at com.sun.jna.Function.invoke(Function.java:390)
    at com.sun.jna.Function.invoke(Function.java:323)
    at com.sun.jna.Library$Handler.invoke(Library.java:236)
    at com.sun.proxy.$Proxy0.SpPumpEvents(Unknown Source)
    at com.shuffle.scplayer.core.SpotifyConnectPlayerImpl$1.run(SpotifyConnectPlayerImpl.java:118)
    at java.lang.Thread.run(Thread.java:745)

I have 0 java knowledge so I don't know how to fix this (it seems to be a ARM java limitation though).

runs OK, but got exceptions

HI
i've got OE 6.0.1 on my rpi2.

everything works fine, (webgui OK, SCPlayer can be listed in my other connect devices, and can listen music on it. but at the start i got these exceptions:

OpenELEC:~ # ./jdk1.8.0_73/bin/java -jar SCPlayer.jar
2016-02-21 20:00:45 WARN ZeroConfServiceAvahiBin:22 - Avahibin error. Zero conf authentication will not be available
java.io.IOException: Cannot run program "avahi-publish": error=2, No such file or directory
at java.lang.ProcessBuilder.start(ProcessBuilder.java:1048)
at java.lang.Runtime.exec(Runtime.java:620)
at java.lang.Runtime.exec(Runtime.java:450)
at java.lang.Runtime.exec(Runtime.java:347)
at com.shuffle.scplayer.core.zeroconf.ZeroConfServiceAvahiBin$1.run(ZeroConfService​AvahiBin.java:20)
at java.lang.Thread.run(Thread.java:745)
Caused by: java.io.IOException: error=2, No such file or directory
at java.lang.UNIXProcess.forkAndExec(Native Method)
at java.lang.UNIXProcess.(UNIXProcess.java:248)
at java.lang.ProcessImpl.start(ProcessImpl.java:134)
at java.lang.ProcessBuilder.start(ProcessBuilder.java:1029)
... 5 more

could you help with this? and ofc, when i close my ssh client off. it stops running :(
zeroconf is enabled

btw thanks for the efforts.
it works fine. except this thing.

Fixed volume

First of all I must say this is a great project!

I got it working on a Raspberry Pi 2 with (plain) Arch Linux Arm installed and using OpenJDK8 (package jdk8-openjdk from official repo).

Not really an issue but I was wondering if it is possible to fix volume level at 100% or bypass volume control altogether.

Thanks!
Hans.

No sound cards available

I'm getting the following error. Can someone help? I'm running openelec on a RP2.

../jdk1.8.0_77/bin/java -jar SCPlayer.jar
2016-03-26 16:41:09 ERROR SpotifyConnectPlayerImpl:110 - No sound cards Avaliables
2016-03-26 16:41:09 ERROR SpotifyConnectPlayerImpl:165 - General error
java.lang.Exception: No sound cards Avaliables
at com.shuffle.scplayer.core.SpotifyConnectPlayerImpl.(SpotifyConnectPlayerImpl.java:111)
at com.shuffle.scplayer.core.SpotifyConnectPlayerImpl.(SpotifyConnectPlayerImpl.java:97)
at com.shuffle.scplayer.SCPlayerMain.main(SCPlayerMain.java:102)
Exception in thread "main" java.lang.IllegalArgumentException: general error
at com.shuffle.scplayer.core.SpotifyConnectPlayerImpl.(SpotifyConnectPlayerImpl.java:166)
at com.shuffle.scplayer.core.SpotifyConnectPlayerImpl.(SpotifyConnectPlayerImpl.java:97)
at com.shuffle.scplayer.SCPlayerMain.main(SCPlayerMain.java:102)
Caused by: java.lang.Exception: No sound cards Avaliables
at com.shuffle.scplayer.core.SpotifyConnectPlayerImpl.(SpotifyConnectPlayerImpl.java:111)
... 2 more

Add systemd service file

I love the project, keep it up! Wanted the service to start on boot, so i added a service file. This one works for me:

[Unit]
Description=Spotify Connect Player
After=network.target

[Service]
ExecStartPre=cd /home/pi/scplayer
ExecStart=/usr/bin/java -Ddebug=0 -Dstandalone=true -Dplayer.name=SCPlayer -Dbitrate=320 -Dusername=XXXXXX -Dpassword=XXXXXX -Dapp.key=./spotify_appkey.key -jar SCPlayer.jar
WorkingDirectory=/home/pi/scplayer

[Install]
WantedBy=multi-user.target

Error running final Java Command

When I go to run the final Java command to complete the process I get this error.

Kodi:~/downloads/SpotifyConnect # ./jdk1.8.0_65/bin/java -jar SCPlayer.jar
./jdk1.8.0_65/bin/java: line 6: syntax error: unexpected ")"

I may have messed up along the way, but these are the files in that "SpotifyConnect" folder

Kodi:~/downloads/SpotifyConnect # ls
SCPlayer.jar                      jdk1.8.0_65                       spotify_appkey.key
jdk-8u65-linux-arm64-vfp-hflt.gz  libspotify_embedded_shared.so

Followed instructions from here: http://forum.kodi.tv/showthread.php?tid=221145 as well

Using zeroconf to authenticate spotify user

Hi,
I'm trying to implement a zeroconf support to scplayer but I have an issue with SpZeroConfVars function from spotify library. I try to get a public key used to cipher user credentials that getInfo method should return to the client but about 1 second after I called SpZeroConfVars (i get results) Java throws SIGSEGV error.

Java code:

SpZeroConfVars vars = new SpZeroConfVars();
int result = spotifyLib.SpZeroConfGetVars(vars);
return vars.publicKey;

error:

# A fatal error has been detected by the Java Runtime Environment:
#
#  SIGSEGV (0xb) at pc=0x68011edc, pid=28775, tid=1728005216
#
# JRE version: Java(TM) SE Runtime Environment (8.0_65-b17) (build 1.8.0_65-b17)
# Java VM: Java HotSpot(TM) Client VM (25.65-b01 mixed mode linux-arm )
# Problematic frame:
# C  [jna1129165445621772155.tmp+0xdedc]

Is there something wrong with my call?

Regards

Not working on RasPi 3

In the Spotify application I can find the SCPlayer I also can play songs on it and access the webinterface.
But no sound is played at all.
The programm is spamming this errormessage:
javax.sound.sampled.LineUnavailableException at org.classpath.icedtea.pulseaudio.PulseAudioMixer.openImpl(PulseAudioMixer.java:714) at org.classpath.icedtea.pulseaudio.PulseAudioMixer.openLocal(PulseAudioMixer.java:588) at org.classpath.icedtea.pulseaudio.PulseAudioMixer.openLocal(PulseAudioMixer.java:584) at org.classpath.icedtea.pulseaudio.PulseAudioMixer.open(PulseAudioMixer.java:579) at org.classpath.icedtea.pulseaudio.PulseAudioDataLine.open(PulseAudioDataLine.java:94) at org.classpath.icedtea.pulseaudio.PulseAudioSourceDataLine.open(PulseAudioSourceDataLine.java:75) at com.shuffle.scplayer.core.AudioPlayer.onActive(AudioPlayer.java:62) at com.shuffle.scplayer.core.AudioPlayer.onPlay(AudioPlayer.java:83) at com.shuffle.scplayer.core.SpotifyConnectPlayerImpl$6.apply(SpotifyConnectPlayerImpl.java:209) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.lang.reflect.Method.invoke(Method.java:483) at com.sun.jna.CallbackReference$DefaultCallbackProxy.invokeCallback(CallbackReference.java:485) at com.sun.jna.CallbackReference$DefaultCallbackProxy.callback(CallbackReference.java:515) at com.sun.jna.Native.invokeInt(Native Method) at com.sun.jna.Function.invoke(Function.java:390) at com.sun.jna.Function.invoke(Function.java:323) at com.sun.jna.Library$Handler.invoke(Library.java:236) at com.sun.proxy.$Proxy0.SpPumpEvents(Unknown Source) at com.shuffle.scplayer.core.SpotifyConnectPlayerImpl$2.run(SpotifyConnectPlayerImpl.java:136) at java.lang.Thread.run(Thread.java:745)

I'm using an RaspberryPi 3 running the latest software, kernel and packages.
Java-Version dump:
openjdk version "1.8.0_40-internal"
OpenJDK Runtime Environment (build 1.8.0_40-internal-b04)
OpenJDK Zero VM (build 25.40-b08, interpreted mode)

Edit: This problem happens on all mixers

ZeroConf is not working

this is my log

2016-04-05 22:29:30 DEBUG SpotifyZeroConfServer:29 - GET: / : getInfo
2016-04-05 22:29:31 DEBUG SpotifyZeroConfServer:29 - GET: / : getInfo
2016-04-05 22:29:31 DEBUG SpotifyZeroConfServer:29 - GET: / : getInfo
2016-04-05 22:29:31 DEBUG SpotifyZeroConfServer:29 - GET: / : getInfo
2016-04-05 22:29:36 DEBUG SpotifyZeroConfServer:29 - GET: / : getInfo
2016-04-05 22:29:41 DEBUG SpotifyZeroConfServer:29 - GET: / : getInfo
2016-04-05 22:29:49 DEBUG SpotifyZeroConfServer:29 - POST: / : addUser

i don't know what should happen afterwards?
when i select the instance on my phone (doesn't show up on my mac...strange) it just hangs on connect.
@vit3k maybe you can help since you coded it

X86 libs/version

This looks great, good work. Maybe stupid but is there a Spotify lib for x86/x86_64 that I could use to get this working on a nuc? If not any idea how to grab one? Guessing these come from the android app but maybe I could grab the so from the android tv that runs x86? Anyone tried?

Poor audio quality

Hey, I have tried your implementation and I have problem that sound quality is really noisy (I am playing 320 bitrate) where can be problem? Latest Raspbian and Raspberry pi 2

buffer underrun without aparent reason..

sometimes when you open and get buffer underrun you have to close and open again to go back to normal..
it happens when you are going to play the first song, if the first played ok never happens after..

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.