当前位置: 首页>>代码示例>>Java>>正文


Java Caller类代码示例

本文整理汇总了Java中de.umass.lastfm.Caller的典型用法代码示例。如果您正苦于以下问题:Java Caller类的具体用法?Java Caller怎么用?Java Caller使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


Caller类属于de.umass.lastfm包,在下文中一共展示了Caller类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: performHandshake

import de.umass.lastfm.Caller; //导入依赖的package包/类
/**
 * Internally performs the handshake operation by calling the given <code>url</code> and examining the response.
 *
 * @param url The URL to call
 * @return the status of the operation
 * @throws IOException on I/O errors
 */
private ResponseStatus performHandshake(String url) throws IOException {
	HttpURLConnection connection = Caller.getInstance().openConnection(url);
	InputStream is = connection.getInputStream();
	BufferedReader r = new BufferedReader(new InputStreamReader(is));
	String status = r.readLine();
	int statusCode = ResponseStatus.codeForStatus(status);
	ResponseStatus responseStatus;
	if (statusCode == ResponseStatus.OK) {
		this.sessionId = r.readLine();
		this.nowPlayingUrl = r.readLine();
		this.submissionUrl = r.readLine();
		responseStatus = new ResponseStatus(statusCode);
	} else if (statusCode == ResponseStatus.FAILED) {
		responseStatus = new ResponseStatus(statusCode, status.substring(status.indexOf(' ') + 1));
	} else {
		return new ResponseStatus(statusCode);
	}
	r.close();
	return responseStatus;
}
 
开发者ID:kawaiiDango,项目名称:pScrobbler,代码行数:28,代码来源:Scrobbler.java

示例2: nowPlaying

import de.umass.lastfm.Caller; //导入依赖的package包/类
/**
 * Submits 'now playing' information. This does not affect the musical profile of the user.
 *
 * @param artist The artist's name
 * @param track The track's title
 * @param album The album or <code>null</code>
 * @param length The length of the track in seconds
 * @param tracknumber The position of the track in the album or -1
 * @return the status of the operation
 * @throws IOException on I/O errors
 */
public ResponseStatus nowPlaying(String artist, String track, String album, int length, int tracknumber) throws
		IOException {
	if (sessionId == null)
		throw new IllegalStateException("Perform successful handshake first.");
	String b = album != null ? encode(album) : "";
	String l = length == -1 ? "" : String.valueOf(length);
	String n = tracknumber == -1 ? "" : String.valueOf(tracknumber);
	String body = String
			.format("s=%s&a=%s&t=%s&b=%s&l=%s&n=%s&m=", sessionId, encode(artist), encode(track), b, l, n);
	if (Caller.getInstance().isDebugMode())
		System.out.println("now playing: " + body);
	HttpURLConnection urlConnection = Caller.getInstance().openConnection(nowPlayingUrl);
	urlConnection.setRequestMethod("POST");
	urlConnection.setDoOutput(true);
	OutputStream outputStream = urlConnection.getOutputStream();
	BufferedWriter writer = new BufferedWriter(new OutputStreamWriter(outputStream));
	writer.write(body);
	writer.close();
	InputStream is = urlConnection.getInputStream();
	BufferedReader r = new BufferedReader(new InputStreamReader(is));
	String status = r.readLine();
	r.close();
	return new ResponseStatus(ResponseStatus.codeForStatus(status));
}
 
开发者ID:kawaiiDango,项目名称:pScrobbler,代码行数:36,代码来源:Scrobbler.java

示例3: onCreate

import de.umass.lastfm.Caller; //导入依赖的package包/类
@Override
public void onCreate() {
  super.onCreate();
  Fabric.with(this, new Crashlytics());
  FlowManager.init(this);
  MobileAds.initialize(this, "ca-app-pub-9985743520520066~4279780475");

  sharedPreferences = PreferenceManager.getDefaultSharedPreferences(this);

  String userAgent =
      String.format(Locale.UK, "%s.%d", BuildConfig.APPLICATION_ID, BuildConfig.VERSION_CODE);
  String sessionKeyKey = getString(R.string.saved_session_key);
  LastfmApi api = new LastfmApi();
  Caller caller = Caller.getInstance();

  if (sharedPreferences.contains(sessionKeyKey)) {
    String sessionKey = sharedPreferences.getString(sessionKeyKey, null);
    lastfmClient = new LastfmClient(api, caller, userAgent, sessionKey);
  } else {
    lastfmClient = new LastfmClient(api, caller, userAgent);
  }

  scroballDB = new ScroballDB();
  eventBus.register(this);
}
 
开发者ID:peterjosling,项目名称:scroball,代码行数:26,代码来源:ScroballApplication.java

示例4: startLastFmSession

import de.umass.lastfm.Caller; //导入依赖的package包/类
public boolean startLastFmSession(String lastFmUsername, String lastFmPassword) {
    // Last fm API set up
    Caller lastFmCaller = Caller.getInstance();
    lastFmCaller.setUserAgent(System.getProperties().getProperty("http.agent"));
    lastFmCaller.setDebugMode(true);
    lastFmCaller.setCache(new MemoryCache());

    try {
        mLastFmSession = Authenticator.getMobileSession(lastFmUsername, lastFmPassword, API_KEY, API_SECRET);
    } catch (Exception e) {
        Log.e(TAG, "Error while getting last.fm session", e);
        return false;
    }

    return mLastFmSession != null;
}
 
开发者ID:sregg,项目名称:spotify-tv,代码行数:17,代码来源:LastFmApi.java

示例5: performHandshake

import de.umass.lastfm.Caller; //导入依赖的package包/类
/**
 * Internally performs the handshake operation by calling the given <code>url</code> and examining the response.
 *
 * @param url The URL to call
 * @return the status of the operation
 * @throws IOException on I/O errors
 */
private ResponseStatus performHandshake(String url) throws IOException {
    HttpURLConnection connection = Caller.getInstance().openConnection(url);
    InputStream is = connection.getInputStream();
    BufferedReader r = new BufferedReader(new InputStreamReader(is));
    String status = r.readLine();
    int statusCode = ResponseStatus.codeForStatus(status);
    ResponseStatus responseStatus;
    if (statusCode == ResponseStatus.OK) {
        this.sessionId = r.readLine();
        this.nowPlayingUrl = r.readLine();
        this.submissionUrl = r.readLine();
        responseStatus = new ResponseStatus(statusCode);
    } else if (statusCode == ResponseStatus.FAILED) {
        responseStatus = new ResponseStatus(statusCode, status.substring(status.indexOf(' ') + 1));
    } else {
        return new ResponseStatus(statusCode);
    }
    r.close();
    return responseStatus;
}
 
开发者ID:OpenSilk,项目名称:Orpheus,代码行数:28,代码来源:Scrobbler.java

示例6: nowPlaying

import de.umass.lastfm.Caller; //导入依赖的package包/类
/**
 * Submits 'now playing' information. This does not affect the musical profile of the user.
 *
 * @param artist The artist's name
 * @param track The track's title
 * @param album The album or <code>null</code>
 * @param length The length of the track in seconds
 * @param tracknumber The position of the track in the album or -1
 * @return the status of the operation
 * @throws IOException on I/O errors
 */
public ResponseStatus nowPlaying(String artist, String track, String album, int length, int tracknumber) throws
        IOException {
    if (sessionId == null)
        throw new IllegalStateException("Perform successful handshake first.");
    String b = album != null ? encode(album) : "";
    String l = length == -1 ? "" : String.valueOf(length);
    String n = tracknumber == -1 ? "" : String.valueOf(tracknumber);
    String body = String
            .format("s=%s&a=%s&t=%s&b=%s&l=%s&n=%s&m=", sessionId, encode(artist), encode(track), b, l, n);
    if (Caller.getInstance().isDebugMode())
        System.out.println("now playing: " + body);
    HttpURLConnection urlConnection = Caller.getInstance().openConnection(nowPlayingUrl);
    urlConnection.setRequestMethod("POST");
    urlConnection.setDoOutput(true);
    OutputStream outputStream = urlConnection.getOutputStream();
    BufferedWriter writer = new BufferedWriter(new OutputStreamWriter(outputStream));
    writer.write(body);
    writer.close();
    InputStream is = urlConnection.getInputStream();
    BufferedReader r = new BufferedReader(new InputStreamReader(is));
    String status = r.readLine();
    r.close();
    return new ResponseStatus(ResponseStatus.codeForStatus(status));
}
 
开发者ID:OpenSilk,项目名称:Orpheus,代码行数:36,代码来源:Scrobbler.java

示例7: Lastfm

import de.umass.lastfm.Caller; //导入依赖的package包/类
public Lastfm(Context context) {
    super(context);
    mContext = context;
    Resources res = context.getResources();

    API_KEY = res.getString(R.string.lastfm_api_key);
    API_SECRET = res.getString(R.string.lastfm_api_secret);
    mPrefs = PreferenceManager.getDefaultSharedPreferences(this);
    mAccessKey = mPrefs.getString("lastfm_access_key", null);
    mUserName = mPrefs.getString("lastfm_user_name", null);

    //if username and key not null -> recreate the lastfm session
    if(mAccessKey != null) {
        mSession = Session.createSession(API_KEY, API_SECRET, mAccessKey);
    }

    String ua = res.getString(R.string.user_agent);

    mLastfm = Caller.getInstance();
    mLastfm.setUserAgent(ua);
    mLastfm.setCache(null);
    mLastfm.setDebugMode(true);
}
 
开发者ID:jvanhie,项目名称:discogsscrobbler,代码行数:24,代码来源:Lastfm.java

示例8: submit

import de.umass.lastfm.Caller; //导入依赖的package包/类
/**
 * Scrobbles up to 50 songs at once. Song info is contained in the <code>Collection</code> passed. Songs must be in
 * chronological order of their play, that means the track first in the list has been played before the track second
 * in the list and so on.
 *
 * @param data A list of song infos
 * @return the status of the operation
 * @throws IOException on I/O errors
 * @throws IllegalArgumentException if data contains more than 50 entries
 */
public ResponseStatus submit(Collection<SubmissionData> data) throws IOException {
	if (sessionId == null)
		throw new IllegalStateException("Perform successful handshake first.");
	if (data.size() > 50)
		throw new IllegalArgumentException("Max 50 submissions at once");
	StringBuilder builder = new StringBuilder(data.size() * 100);
	int index = 0;
	for (SubmissionData submissionData : data) {
		builder.append(submissionData.toString(sessionId, index));
		builder.append('\n');
		index++;
	}
	String body = builder.toString();
	if (Caller.getInstance().isDebugMode())
		System.out.println("submit: " + body);
	HttpURLConnection urlConnection = Caller.getInstance().openConnection(submissionUrl);
	urlConnection.setRequestMethod("POST");
	urlConnection.setDoOutput(true);
	OutputStream outputStream = urlConnection.getOutputStream();
	BufferedWriter writer = new BufferedWriter(new OutputStreamWriter(outputStream));
	writer.write(body);
	writer.close();
	InputStream is = urlConnection.getInputStream();
	BufferedReader r = new BufferedReader(new InputStreamReader(is));
	String status = r.readLine();
	r.close();
	int statusCode = ResponseStatus.codeForStatus(status);
	if (statusCode == ResponseStatus.FAILED) {
		return new ResponseStatus(statusCode, status.substring(status.indexOf(' ') + 1));
	}
	return new ResponseStatus(statusCode);
}
 
开发者ID:kawaiiDango,项目名称:pScrobbler,代码行数:43,代码来源:Scrobbler.java

示例9: LastfmClient

import de.umass.lastfm.Caller; //导入依赖的package包/类
/**
 * Creates a new unauthenticated client. The only allowed client method on this instance will be
 * {@link #getSession(String, Handler.Callback)}
 */
public LastfmClient(LastfmApi api, Caller caller, String userAgent) {
  this.api = api;
  this.caller = caller;
  caller.setUserAgent(userAgent);
  caller.setCache(null);
}
 
开发者ID:peterjosling,项目名称:scroball,代码行数:11,代码来源:LastfmClient.java

示例10: init

import de.umass.lastfm.Caller; //导入依赖的package包/类
public void init() {
    Caller caller = Caller.getInstance();
    caller.setUserAgent("Subsonic");

    File cacheDir = new File(SettingsService.getSubsonicHome(), "lastfmcache");
    caller.setCache(new LastFmCache(cacheDir, CACHE_TIME_TO_LIVE_MILLIS));
}
 
开发者ID:sindremehus,项目名称:subsonic,代码行数:8,代码来源:LastFmService.java

示例11: submit

import de.umass.lastfm.Caller; //导入依赖的package包/类
/**
 * Scrobbles up to 50 songs at once. Song info is contained in the <code>Collection</code> passed. Songs must be in
 * chronological order of their play, that means the track first in the list has been played before the track second
 * in the list and so on.
 *
 * @param data A list of song infos
 * @return the status of the operation
 * @throws IOException on I/O errors
 * @throws IllegalArgumentException if data contains more than 50 entries
 */
public ResponseStatus submit(Collection<SubmissionData> data) throws IOException {
    if (sessionId == null)
        throw new IllegalStateException("Perform successful handshake first.");
    if (data.size() > 50)
        throw new IllegalArgumentException("Max 50 submissions at once");
    StringBuilder builder = new StringBuilder(data.size() * 100);
    int index = 0;
    for (SubmissionData submissionData : data) {
        builder.append(submissionData.toString(sessionId, index));
        builder.append('\n');
        index++;
    }
    String body = builder.toString();
    if (Caller.getInstance().isDebugMode())
        System.out.println("submit: " + body);
    HttpURLConnection urlConnection = Caller.getInstance().openConnection(submissionUrl);
    urlConnection.setRequestMethod("POST");
    urlConnection.setDoOutput(true);
    OutputStream outputStream = urlConnection.getOutputStream();
    BufferedWriter writer = new BufferedWriter(new OutputStreamWriter(outputStream));
    writer.write(body);
    writer.close();
    InputStream is = urlConnection.getInputStream();
    BufferedReader r = new BufferedReader(new InputStreamReader(is));
    String status = r.readLine();
    r.close();
    int statusCode = ResponseStatus.codeForStatus(status);
    if (statusCode == ResponseStatus.FAILED) {
        return new ResponseStatus(statusCode, status.substring(status.indexOf(' ') + 1));
    }
    return new ResponseStatus(statusCode);
}
 
开发者ID:OpenSilk,项目名称:Orpheus,代码行数:43,代码来源:Scrobbler.java

示例12: fetchTrackDurationAndSubmit

import de.umass.lastfm.Caller; //导入依赖的package包/类
public void fetchTrackDurationAndSubmit(final PlaybackItem playbackItem) {
  NetworkInfo activeNetwork = connectivityManager.getActiveNetworkInfo();
  boolean isConnected = activeNetwork != null && activeNetwork.isConnectedOrConnecting();

  if (!isConnected || !client.isAuthenticated()) {
    Log.d(TAG, "Offline or unauthenticated, can't fetch track duration. Saving for later.");
    queuePendingPlaybackItem(playbackItem);
    return;
  }

  Track track = playbackItem.getTrack();
  client.getTrackInfo(
      track,
      message -> {
        if (message.obj == null) {
          Result result = Caller.getInstance().getLastResult();
          int errorCode = 1;

          if (result != null) {
            errorCode = result.getErrorCode();
          }
          if (errorCode == 6) {
            Log.d(TAG, "Track not found, cannot scrobble.");
            // TODO prompt user to scrobble anyway
          } else {
            if (LastfmClient.isTransientError(errorCode)) {
              Log.d(TAG, "Failed to fetch track duration, saving for later.");
              queuePendingPlaybackItem(playbackItem);
            }
            if (LastfmClient.isAuthenticationError(errorCode)) {
              notificationManager.notifyAuthError();
              ScroballApplication.getEventBus().post(AuthErrorEvent.create(errorCode));
            }
          }
          return true;
        }

        Track updatedTrack = (Track) message.obj;
        playbackItem.updateTrack(updatedTrack);
        Log.d(TAG, String.format("Track info updated: %s", playbackItem));

        submit(playbackItem);
        return true;
      });
}
 
开发者ID:peterjosling,项目名称:scroball,代码行数:46,代码来源:Scrobbler.java

示例13: GetSessionTask

import de.umass.lastfm.Caller; //导入依赖的package包/类
public GetSessionTask(LastfmApi api, Caller caller, Handler.Callback callback) {
  this.api = api;
  this.caller = caller;
  this.callback = callback;
}
 
开发者ID:peterjosling,项目名称:scroball,代码行数:6,代码来源:LastfmClient.java

示例14: getComm

import de.umass.lastfm.Caller; //导入依赖的package包/类
public static LastfmComm getComm(){
	Caller.getInstance().setCache(null);
	return comm;
}
 
开发者ID:helderm,项目名称:songseeker,代码行数:5,代码来源:LastfmComm.java

示例15: Lastfm

import de.umass.lastfm.Caller; //导入依赖的package包/类
public Lastfm() {

        Caller.getInstance().setUserAgent("tst");

    }
 
开发者ID:Walkersneps,项目名称:SnepsBotX,代码行数:6,代码来源:Lastfm.java


注:本文中的de.umass.lastfm.Caller类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。