Search in sources :

Example 6 with CreateLiveChannelRequest

use of com.aliyun.oss.model.CreateLiveChannelRequest in project aliyun-oss-java-sdk by aliyun.

the class RtmpTest method testDeleteLiveChannel.

@Test
public void testDeleteLiveChannel() {
    final String liveChannel = "normal-delete-live-channel";
    try {
        CreateLiveChannelRequest createLiveChannelRequest = new CreateLiveChannelRequest(bucketName, liveChannel);
        ossClient.createLiveChannel(createLiveChannelRequest);
        ossClient.getLiveChannelInfo(bucketName, liveChannel);
        ossClient.deleteLiveChannel(bucketName, liveChannel);
        try {
            ossClient.getLiveChannelInfo(bucketName, liveChannel);
        } catch (OSSException e) {
            Assert.assertEquals(e.getErrorCode(), OSSErrorCode.NO_SUCH_LIVE_CHANNEL);
        }
    } catch (Exception e) {
        Assert.fail(e.getMessage());
    }
}
Also used : CreateLiveChannelRequest(com.aliyun.oss.model.CreateLiveChannelRequest) OSSException(com.aliyun.oss.OSSException) OSSException(com.aliyun.oss.OSSException) ParseException(java.text.ParseException) Test(org.junit.Test)

Example 7 with CreateLiveChannelRequest

use of com.aliyun.oss.model.CreateLiveChannelRequest in project aliyun-oss-java-sdk by aliyun.

the class RtmpTest method testCreateLiveChannelDefault.

@Test
public void testCreateLiveChannelDefault() {
    final String liveChannel = "normal-create-live-channel-default";
    try {
        CreateLiveChannelRequest createLiveChannelRequest = new CreateLiveChannelRequest(bucketName, liveChannel);
        CreateLiveChannelResult createLiveChannelResult = ossClient.createLiveChannel(createLiveChannelRequest);
        Assert.assertEquals(createLiveChannelResult.getPublishUrls().size(), 1);
        Assert.assertTrue(createLiveChannelResult.getPublishUrls().get(0).startsWith("rtmp://"));
        Assert.assertTrue(createLiveChannelResult.getPublishUrls().get(0).endsWith("live/" + liveChannel));
        Assert.assertEquals(createLiveChannelResult.getPlayUrls().size(), 1);
        Assert.assertTrue(createLiveChannelResult.getPlayUrls().get(0).startsWith("http://"));
        Assert.assertTrue(createLiveChannelResult.getPlayUrls().get(0).endsWith(liveChannel + "/playlist.m3u8"));
        Assert.assertEquals(createLiveChannelResult.getRequestId().length(), REQUEST_ID_LEN);
        LiveChannelInfo liveChannelInfo = ossClient.getLiveChannelInfo(bucketName, liveChannel);
        Assert.assertEquals(liveChannelInfo.getDescription(), "");
        Assert.assertEquals(liveChannelInfo.getStatus(), LiveChannelStatus.Enabled);
        Assert.assertEquals(liveChannelInfo.getTarget().getType(), "HLS");
        Assert.assertEquals(liveChannelInfo.getTarget().getFragDuration(), 5);
        Assert.assertEquals(liveChannelInfo.getTarget().getFragCount(), 3);
        Assert.assertEquals(liveChannelInfo.getTarget().getPlaylistName(), "playlist.m3u8");
        Assert.assertEquals(liveChannelInfo.getRequestId().length(), REQUEST_ID_LEN);
        ossClient.deleteLiveChannel(bucketName, liveChannel);
    } catch (Exception e) {
        Assert.fail(e.getMessage());
    }
}
Also used : CreateLiveChannelResult(com.aliyun.oss.model.CreateLiveChannelResult) LiveChannelInfo(com.aliyun.oss.model.LiveChannelInfo) CreateLiveChannelRequest(com.aliyun.oss.model.CreateLiveChannelRequest) OSSException(com.aliyun.oss.OSSException) ParseException(java.text.ParseException) Test(org.junit.Test)

Example 8 with CreateLiveChannelRequest

use of com.aliyun.oss.model.CreateLiveChannelRequest in project aliyun-oss-java-sdk by aliyun.

the class RtmpTest method testGetLiveChannelHistory.

@Ignore
public void testGetLiveChannelHistory() {
    final String liveChannel = "normal-get-live-channel-history";
    try {
        CreateLiveChannelRequest createLiveChannelRequest = new CreateLiveChannelRequest(bucketName, liveChannel);
        ossClient.createLiveChannel(createLiveChannelRequest);
        ossClient.setBucketAcl(bucketName, CannedAccessControlList.PublicReadWrite);
        // Manually enable pusing streaming with following cmd:
        // ./ffmpeg \-re \-i allstar.flv \-c copy \-f flv "rtmp://oss-live-channel-2.demo-oss-cn-shenzhen.aliyuncs.com/live/normal-get-live-channel-history?playlistName=playlist.m3u8"
        Thread.sleep(5 * 1000);
        List<LiveRecord> liveRecords = ossClient.getLiveChannelHistory(bucketName, liveChannel);
        Assert.assertTrue(liveRecords.size() >= 1);
        for (LiveRecord liveRecord : liveRecords) {
            Assert.assertTrue(dateAfterValidator(liveRecord.getStartDate()));
            Assert.assertTrue(dateAfterValidator(liveRecord.getEndDate()));
            Assert.assertTrue(liveRecord.getRemoteAddress().length() >= new String("0.0.0.0:0").length());
        }
    } catch (Exception e) {
        Assert.fail(e.getMessage());
    }
}
Also used : LiveRecord(com.aliyun.oss.model.LiveRecord) CreateLiveChannelRequest(com.aliyun.oss.model.CreateLiveChannelRequest) OSSException(com.aliyun.oss.OSSException) ParseException(java.text.ParseException) Ignore(org.junit.Ignore)

Example 9 with CreateLiveChannelRequest

use of com.aliyun.oss.model.CreateLiveChannelRequest in project aliyun-oss-java-sdk by aliyun.

the class RtmpTest method testUnormalCreateLiveChannel.

@Test
public void testUnormalCreateLiveChannel() {
    final String liveChannel = "unnormal-create-live-channel";
    try {
        LiveChannelTarget target = new LiveChannelTarget("RTMP", "myplaylist.m3u8");
        CreateLiveChannelRequest createLiveChannelRequest = new CreateLiveChannelRequest(bucketName, liveChannel, "", LiveChannelStatus.Enabled, target);
        ossClient.createLiveChannel(createLiveChannelRequest);
        Assert.fail("Get live channel should not be successful.");
    } catch (OSSException e) {
        Assert.assertEquals(e.getErrorCode(), OSSErrorCode.INVALID_ARGUMENT);
    }
    try {
        LiveChannelTarget target = new LiveChannelTarget("HLS", 200, 99, "myplaylist.m3u8");
        CreateLiveChannelRequest createLiveChannelRequest = new CreateLiveChannelRequest(bucketName, liveChannel, "", LiveChannelStatus.Enabled, target);
        ossClient.createLiveChannel(createLiveChannelRequest);
        Assert.fail("Get live channel should not be successful.");
    } catch (OSSException e) {
        Assert.assertEquals(e.getErrorCode(), OSSErrorCode.INVALID_ARGUMENT);
    }
    try {
        LiveChannelTarget target = new LiveChannelTarget("HLS", 100, 0, "myplaylist.m3u8");
        CreateLiveChannelRequest createLiveChannelRequest = new CreateLiveChannelRequest(bucketName, liveChannel, "", LiveChannelStatus.Enabled, target);
        ossClient.createLiveChannel(createLiveChannelRequest);
        Assert.fail("Get live channel should not be successful.");
    } catch (OSSException e) {
        Assert.assertEquals(e.getErrorCode(), OSSErrorCode.INVALID_ARGUMENT);
    }
    try {
        LiveChannelTarget target = new LiveChannelTarget("HLS", 100, 199, "myplaylist.m3u8");
        CreateLiveChannelRequest createLiveChannelRequest = new CreateLiveChannelRequest(bucketName, liveChannel, "", LiveChannelStatus.Enabled, target);
        ossClient.createLiveChannel(createLiveChannelRequest);
        Assert.fail("Get live channel should not be successful.");
    } catch (OSSException e) {
        Assert.assertEquals(e.getErrorCode(), OSSErrorCode.INVALID_ARGUMENT);
    }
}
Also used : CreateLiveChannelRequest(com.aliyun.oss.model.CreateLiveChannelRequest) OSSException(com.aliyun.oss.OSSException) LiveChannelTarget(com.aliyun.oss.model.LiveChannelTarget) Test(org.junit.Test)

Example 10 with CreateLiveChannelRequest

use of com.aliyun.oss.model.CreateLiveChannelRequest in project aliyun-oss-java-sdk by aliyun.

the class RtmpTest method testGenerateVodPlaylist.

@Test
public void testGenerateVodPlaylist() {
    final String liveChannel = "normal-generate-vod-playlist";
    try {
        CreateLiveChannelRequest createLiveChannelRequest = new CreateLiveChannelRequest(bucketName, liveChannel);
        ossClient.createLiveChannel(createLiveChannelRequest);
        ossClient.setBucketAcl(bucketName, CannedAccessControlList.PublicReadWrite);
        long startTime = System.currentTimeMillis() / 1000 - 3600;
        long endTime = System.currentTimeMillis() / 1000 + 3600;
        try {
            ossClient.generateVodPlaylist(bucketName, liveChannel, "playlist.m3u8", startTime, endTime);
        } catch (OSSException e) {
            Assert.assertEquals(e.getErrorCode(), OSSErrorCode.INVALID_ARGUMENT);
            Assert.assertTrue(e.getMessage().indexOf("No ts file found in specified time span.") > -1);
        }
        ossClient.deleteLiveChannel(bucketName, liveChannel);
    } catch (Exception e) {
        Assert.fail(e.getMessage());
    }
}
Also used : CreateLiveChannelRequest(com.aliyun.oss.model.CreateLiveChannelRequest) OSSException(com.aliyun.oss.OSSException) OSSException(com.aliyun.oss.OSSException) ParseException(java.text.ParseException) Test(org.junit.Test)

Aggregations

OSSException (com.aliyun.oss.OSSException)14 CreateLiveChannelRequest (com.aliyun.oss.model.CreateLiveChannelRequest)14 ParseException (java.text.ParseException)13 Test (org.junit.Test)12 LiveChannelInfo (com.aliyun.oss.model.LiveChannelInfo)6 LiveChannelTarget (com.aliyun.oss.model.LiveChannelTarget)3 CreateLiveChannelResult (com.aliyun.oss.model.CreateLiveChannelResult)2 LiveChannelStat (com.aliyun.oss.model.LiveChannelStat)2 LiveRecord (com.aliyun.oss.model.LiveRecord)2 Ignore (org.junit.Ignore)2 ListLiveChannelsRequest (com.aliyun.oss.model.ListLiveChannelsRequest)1 LiveChannel (com.aliyun.oss.model.LiveChannel)1 LiveChannelListing (com.aliyun.oss.model.LiveChannelListing)1