如何通过Android在线播放音乐?

时间:2014-02-21 07:46:40

标签: java android android-layout streaming android-view

我今天一直在做一些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();


        }}

谢谢!

1 个答案:

答案 0 :(得分:1)

您可以从本教程中获得答案

查看此链接:

http://www.youtube.com/watch?v=J3kwFMkAsJ0&list=PL14AA2548E3C96B50