Search in sources :

Example 1 with LiveRecord

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

the class RtmpTest method testGetLiveChannelHistoryWithoutPushflow.

@Test
public void testGetLiveChannelHistoryWithoutPushflow() {
    final String liveChannel = "normal-get-live-channel-history-without-pushflow";
    try {
        CreateLiveChannelRequest createLiveChannelRequest = new CreateLiveChannelRequest(bucketName, liveChannel);
        ossClient.createLiveChannel(createLiveChannelRequest);
        List<LiveRecord> liveRecords = ossClient.getLiveChannelHistory(bucketName, liveChannel);
        Assert.assertEquals(liveRecords.size(), 0);
        ossClient.deleteLiveChannel(bucketName, liveChannel);
    } 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) Test(org.junit.Test)

Example 2 with LiveRecord

use of com.aliyun.oss.model.LiveRecord 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 3 with LiveRecord

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

the class ResponseParsers method parseGetLiveChannelHistory.

/**
 * Unmarshall get live channel history response body to corresponding
 * result.
 */
@SuppressWarnings("unchecked")
public static List<LiveRecord> parseGetLiveChannelHistory(InputStream responseBody) throws ResponseParseException {
    try {
        Element root = getXmlRootElement(responseBody);
        List<LiveRecord> liveRecords = new ArrayList<LiveRecord>();
        List<Element> recordElements = root.getChildren("LiveRecord");
        for (Element recordElem : recordElements) {
            LiveRecord record = new LiveRecord();
            record.setStartDate(DateUtil.parseIso8601Date(recordElem.getChildText("StartTime")));
            record.setEndDate(DateUtil.parseIso8601Date(recordElem.getChildText("EndTime")));
            record.setRemoteAddress(recordElem.getChildText("RemoteAddr"));
            liveRecords.add(record);
        }
        return liveRecords;
    } catch (JDOMParseException e) {
        throw new ResponseParseException(e.getPartialDocument() + ": " + e.getMessage(), e);
    } catch (Exception e) {
        throw new ResponseParseException(e.getMessage(), e);
    }
}
Also used : JDOMParseException(org.jdom.input.JDOMParseException) Element(org.jdom.Element) LiveRecord(com.aliyun.oss.model.LiveRecord) ResponseParseException(com.aliyun.oss.common.parser.ResponseParseException) ArrayList(java.util.ArrayList) ParseException(java.text.ParseException) JDOMParseException(org.jdom.input.JDOMParseException) ResponseParseException(com.aliyun.oss.common.parser.ResponseParseException)

Aggregations

LiveRecord (com.aliyun.oss.model.LiveRecord)3 ParseException (java.text.ParseException)3 OSSException (com.aliyun.oss.OSSException)2 CreateLiveChannelRequest (com.aliyun.oss.model.CreateLiveChannelRequest)2 ResponseParseException (com.aliyun.oss.common.parser.ResponseParseException)1 ArrayList (java.util.ArrayList)1 Element (org.jdom.Element)1 JDOMParseException (org.jdom.input.JDOMParseException)1 Ignore (org.junit.Ignore)1 Test (org.junit.Test)1