add user input
[rtmpclient.git] / app / src / main / java / ai / suanzi / rtmpclient / MyService.java
index 768d95d..c2886ff 100644 (file)
@@ -17,24 +17,26 @@ public class MyService extends Service {
     private static final String TAG = "MyService";
     private Ffmpeg ffmpeg = Ffmpeg.getInstance();
     private  Boolean isRunning = false;
-
-    private Runnable runnable = new Runnable() {
+    //private String url = "rtmp://gpussh.suanzi.ai:1935/myapp/suanzi_ac83f34ead90_cameraid";
+    private FfmpegRunnable  runnable;
+    private class FfmpegRunnable implements Runnable {
+        private String url;
+        public FfmpegRunnable(String _url){
+            this.url = _url;
+        }
         @Override
-        public void run() {
-            Log.e(TAG, "Run ffmpeg");
+        public void run(){
+            Log.e(TAG, "Run ffmpeg, url: " + url);
             isRunning = true;
-            ffmpeg.push(null);
+            ffmpeg.push(null, this.url);
         }
-    };
-
+    }
 
     /**
      * id不可设置为0,否则不能设置为前台service
      */
     private static final int NOTIFICATION_DOWNLOAD_PROGRESS_ID = 0x0001;
 
-    //private boolean isRemove=false;//是否需要移除
-
     /**
      * Notification
      */
@@ -92,26 +94,16 @@ public class MyService extends Service {
     @Override
     public int onStartCommand(Intent intent, int flags, int startId) {
         Log.e(TAG, "onStartCommand");
+
+        String url = intent.getExtras().getString("url");
+        Log.e(TAG, "Url is: " + url);
+        runnable = new FfmpegRunnable(url);
+        //this.url = url;
         if (!isRunning) {
             createNotification();
-            Toast.makeText(this, "Ffmpeg started", Toast.LENGTH_LONG).show();
+            Toast.makeText(this, "Video stream pushed to " + url, Toast.LENGTH_LONG).show();
             new Thread(runnable).start();
         }
-
-//        int i=intent.getExtras().getInt("cmd");
-//        if(i==0){
-//            if(!isRemove) {
-//
-//                createNotification();
-//            }
-//            isRemove=true;
-//        }else {
-//            //移除前台服务
-//            if (isRemove) {
-//                stopForeground(true);
-//            }
-//            isRemove=false;
-//        }
         //super.onStartCommand(intent, flags, startId);
         return START_STICKY;
     }
@@ -121,5 +113,4 @@ public class MyService extends Service {
         super.onLowMemory();
         Log.e(TAG, "onLowMemory");
     }
-
 }