1 package ai.suanzi.rtmpclient;
3 import android.app.Service;
4 import android.content.Intent;
5 import android.os.Handler;
6 import android.os.HandlerThread;
7 import android.os.IBinder;
8 import android.os.Looper;
9 import android.util.Log;
10 import android.widget.Toast;
11 import android.support.v4.app.NotificationCompat;
12 import android.graphics.BitmapFactory;
13 import android.app.Notification;
14 import android.os.Message;
16 public class MyService extends Service {
17 private static final String TAG = "MyService";
18 private Ffmpeg ffmpeg = Ffmpeg.getInstance();
19 private Boolean isRunning = false;
21 private Runnable runnable = new Runnable() {
24 Log.e(TAG, "Run ffmpeg");
32 * id不可设置为0,否则不能设置为前台service
34 private static final int NOTIFICATION_DOWNLOAD_PROGRESS_ID = 0x0001;
36 //private boolean isRemove=false;//是否需要移除
41 public void createNotification(){
42 Log.e(TAG, "create notification");
44 NotificationCompat.Builder builder=new NotificationCompat.Builder(this);
46 builder.setSmallIcon(R.mipmap.ic_launcher);
48 builder.setLargeIcon(BitmapFactory.decodeResource(getResources(),R.drawable.ic_launcher_background));
50 builder.setAutoCancel(false);
52 builder.setOngoing(true);
54 builder.setShowWhen(true);
56 builder.setContentTitle("Rtmp Foreground Service!!!");
58 Notification notification = builder.build();
60 startForeground(NOTIFICATION_DOWNLOAD_PROGRESS_ID,notification);
66 public IBinder onBind(Intent intent) {
71 public void onCreate() {
73 Log.e(TAG, "onCreate");
77 public void onDestroy() {
79 Toast.makeText(this, "MyService Stopped", Toast.LENGTH_LONG).show();
80 Log.e(TAG, "onDestroy");
86 public void onStart(Intent intent, int startid){
87 super.onStart(intent, startid);
88 Log.e(TAG, "onStart");
93 public int onStartCommand(Intent intent, int flags, int startId) {
94 Log.e(TAG, "onStartCommand");
97 Toast.makeText(this, "Ffmpeg started", Toast.LENGTH_LONG).show();
98 new Thread(runnable).start();
101 // int i=intent.getExtras().getInt("cmd");
105 // createNotification();
111 // stopForeground(true);
115 //super.onStartCommand(intent, flags, startId);
120 public void onLowMemory(){
122 Log.e(TAG, "onLowMemory");