我今天一直在做一些Android的东西,不管怎么说我不知道如何让一首歌或应用程序在后台运行我现在想要存档的是从我的电台开始流式传输一个shoutcast服务器。
我该怎么做?
package com.example;
import android.app.Service;
import android.content.Intent;
import android.media.MediaPlayer;
import android.os.IBinder;
import android.util.Log;
import android.widget.Toast;
public class MyService extends Service {
private static final String TAG = "MyService";
MediaPlayer player;
@Override
public IBinder onBind(Intent intent) {
return null;
}
@Override
public void onCreate() {
Toast.makeText(this, "Streaming Started", Toast.LENGTH_LONG).show();
Log.d(TAG, "onCreate");
player = MediaPlayer.create(this, R.raw.braincandy);
player.setLooping(false); // Set looping
}
@Override
public void onDestroy() {
Toast.makeText(this, "Thanks for listening in!", Toast.LENGTH_LONG).show();
Log.d(TAG, "onDestroy");
player.stop();
}
@Override
public void onStart(Intent intent, int startid) {
Toast.makeText(this, "Streaming Started", Toast.LENGTH_LONG).show();
Log.d(TAG, "onStart");
player.start();
}}
谢谢!
答案 0 :(得分:1)