Exemplo n.º 1
0
        public void Stream_saveas()
        {
            Hub    hub    = Hub.Create(ACCESS_KEY, SECRET_KEY, HUB_NAME);
            Stream stream = null;

            string saveAsFormat = "mp4";                            // required
            string saveAsName   = "videoName" + "." + saveAsFormat; // required

            //long saveAsStart = 1444897613; // required, in second, unix timestampstart:1444897613,end:1444897973
            //long saveAsEnd = 1444897973; // required, in second, unix timestamp
            //string saveAsNotifyUrl = null; // optional
            try
            {
                stream = hub.getStream("z1." + HUB_NAME + "." + testStreamName);
                Stream.Status status = stream.status();

                Stream.SaveAsResponse response = stream.saveAs(saveAsName, saveAsFormat);
                Console.WriteLine("Stream saveAs()");
                Console.WriteLine(response.ToString());

                /*
                 *               {
                 *                   "url":"http://ey636h.vod1.z1.pili.qiniucdn.com/recordings/z1.test-hub.55d81a72e3ba5723280000ec/videoName.m3u8",
                 *                   "targetUrl":"http://ey636h.vod1.z1.pili.qiniucdn.com/recordings/z1.test-hub.55d81a72e3ba5723280000ec/videoName.mp4",
                 *                   "persistentId":"z1.55d81c6c7823de5a49ad77b3"
                 *               }
                 */
            }
            catch (PiliException e)
            {
                Assert.Fail();
            }
        }
Exemplo n.º 2
0
        public static void testStream(string streamid)
        {
            Stream      stream      = null;
            Credentials credentials = new Credentials(ACCESS_KEY, SECRET_KEY); // Credentials Object
            Hub         hub         = new Hub(credentials, HUB_NAME);

            //get a stream
            try
            {
                stream = hub.getStream(streamid);
                Console.WriteLine("hub.getStream:");
                Console.WriteLine(stream.toJsonString());

                /*
                 * {
                 *    "id": "z1.liuhanlin.562f2b35d409d2aa48001102",
                 *    "createdAt": "2015-10-27T07:43:49.756Z",
                 *    "updatedAt": "2015-10-27T07:43:49.756Z",
                 *    "title": "562f2b35d409d2aa48001102",
                 *    "hub": "liuhanlin",
                 *    "disabled": false,
                 *    "publishKey": "9654c11a01b7b941",
                 *    "publishSecurity": "static",
                 *    "hosts": {
                 *      "publish": {
                 *        "rtmp": "100000p.publish.z1.pili.qiniup.com"
                 *      },
                 *      "live": {
                 *        "hdl": "100000p.live1-hdl.z1.pili.qiniucdn.com",
                 *        "hls": "100000p.live1-hls.z1.pili.qiniucdn.com",
                 *        "http": "100000p.live1-hls.z1.pili.qiniucdn.com",
                 *        "rtmp": "100000p.live1-rtmp.z1.pili.qiniucdn.com"
                 *      },
                 *      "playback": {
                 *        "hls": "100000p.playback1.z1.pili.qiniucdn.com",
                 *        "http": "100000p.playback1.z1.pili.qiniucdn.com"
                 *      },
                 *      "play": {
                 *        "http": "100000p.live1-hls.z1.pili.qiniucdn.com",
                 *        "rtmp": "100000p.live1-rtmp.z1.pili.qiniucdn.com"
                 *      }
                 *    }
                 *  }
                 */
            }
            catch (PiliException e)
            {
                // TODO Auto-generated catch block
                Console.WriteLine(e.ToString());
                Console.Write(e.StackTrace);
            }
            //// Get Stream segments
            try
            {
                long start = 0; // optional, in second, unix timestamp
                long end   = 0; // optional, in second, unix timestamp
                int  limit = 0; // optional, int
                Stream.SegmentList segmentList = stream.segments(start, end, limit);

                Console.WriteLine("Stream segments()");
                foreach (Stream.Segment segment in segmentList.getSegmentList())
                {
                    Console.WriteLine("start:" + segment.Start + ",end:" + segment.End);
                }

                /*
                 *   start:1440315411,end:1440315435
                 */
            }
            catch (PiliException e)
            {
                // TODO Auto-generated catch block
                Console.WriteLine(e.ToString());
                Console.Write(e.StackTrace);
            }

            // Snapshot Stream
            string format    = "jpg";                      // required
            string name      = "imageName" + "." + format; // required
            long   time      = 1440315411;                 // optional, in second, unix timestamp
            string notifyUrl = null;                       // optional

            try
            {
                Stream.SnapshotResponse response = stream.snapshot(name, format, time, notifyUrl);
                Console.WriteLine("Stream snapshot()");
                Console.WriteLine(response.ToString());

                /*
                 * {
                 *   "targetUrl":"http://ey636h.static1.z0.pili.qiniucdn.com/snapshots/z1.test-hub.55d81a72e3ba5723280000ec/imageName.jpg",
                 *   "persistentId":"z1.55d81c247823de5a49ad729c"
                 * }
                 */
            }
            catch (PiliException e)
            {
                // TODO Auto-generated catch block
                Console.WriteLine(e.ToString());
                Console.Write(e.StackTrace);
            }

            // Save Stream as a file
            string saveAsFormat    = "mp4";                            // required
            string saveAsName      = "videoName" + "." + saveAsFormat; // required
            long   saveAsStart     = 1444897613;                       // required, in second, unix timestampstart:1444897613,end:1444897973
            long   saveAsEnd       = 1444897973;                       // required, in second, unix timestamp
            string saveAsNotifyUrl = null;                             // optional
            string pipleline       = null;

            try
            {
                Stream.SaveAsResponse response = stream.saveAs(saveAsName, saveAsFormat, saveAsStart, saveAsEnd, saveAsNotifyUrl, pipleline);
                Console.WriteLine("Stream saveAs()");
                Console.WriteLine(response.ToString());

                /*
                 * {
                 *   "url":"http://ey636h.vod1.z1.pili.qiniucdn.com/recordings/z1.test-hub.55d81a72e3ba5723280000ec/videoName.m3u8",
                 *   "targetUrl":"http://ey636h.vod1.z1.pili.qiniucdn.com/recordings/z1.test-hub.55d81a72e3ba5723280000ec/videoName.mp4",
                 *   "persistentId":"z1.55d81c6c7823de5a49ad77b3"
                 * }
                 */
            }
            catch (PiliException e)
            {
                // TODO Auto-generated catch block
                Console.WriteLine(e.ToString());
                Console.Write(e.StackTrace);
            }

            // Delete a Stream
            try
            {
                string res = stream.delete();
                Console.WriteLine("Stream delete()");
                Console.WriteLine(res);
                // No Content
            }
            catch (PiliException e)
            {
                // TODO Auto-generated catch block
                Console.WriteLine(e.ToString());
                Console.Write(e.StackTrace);
            }
            //////////////////////////////////////////////////////////////////////////////////////////
            // Stream end

            //get a stream
            try
            {
                stream = hub.getStream(streamid);
                Console.WriteLine("hub.getStream:");
                Console.WriteLine(stream.toJsonString());

                /*
                 * {
                 *    "id": "z1.liuhanlin.562f2b35d409d2aa48001102",
                 *    "createdAt": "2015-10-27T07:43:49.756Z",
                 *    "updatedAt": "2015-10-27T07:43:49.756Z",
                 *    "title": "562f2b35d409d2aa48001102",
                 *    "hub": "liuhanlin",
                 *    "disabled": false,
                 *    "publishKey": "9654c11a01b7b941",
                 *    "publishSecurity": "static",
                 *    "hosts": {
                 *      "publish": {
                 *        "rtmp": "100000p.publish.z1.pili.qiniup.com"
                 *      },
                 *      "live": {
                 *        "hdl": "100000p.live1-hdl.z1.pili.qiniucdn.com",
                 *        "hls": "100000p.live1-hls.z1.pili.qiniucdn.com",
                 *        "http": "100000p.live1-hls.z1.pili.qiniucdn.com",
                 *        "rtmp": "100000p.live1-rtmp.z1.pili.qiniucdn.com"
                 *      },
                 *      "playback": {
                 *        "hls": "100000p.playback1.z1.pili.qiniucdn.com",
                 *        "http": "100000p.playback1.z1.pili.qiniucdn.com"
                 *      },
                 *      "play": {
                 *        "http": "100000p.live1-hls.z1.pili.qiniucdn.com",
                 *        "rtmp": "100000p.live1-rtmp.z1.pili.qiniucdn.com"
                 *      }
                 *    }
                 *  }
                 */
            }
            catch (PiliException e)
            {
                // TODO Auto-generated catch block
                Console.WriteLine(e.ToString());
                Console.Write(e.StackTrace);
            }
        }