PlayNPlay ASP 예시 코드

playnplay 객체를 통해 영상을 재생 or 다운로드하기 위해서 재생 url과 인증 정보 등 필요한 객체를 생성해야 합니다.

1. Streaming 처리 부분

아래는 스트리밍 영상을 재생하기 위한 JSON 객체를 생성하는 .NET ASP 코드 예시입니다.

이 코드는 .NET Framework 3.5 이상, C# 3.0 이상에서 지원하는 Newtonsoft.Json 라이브러리를 사용합니다.makeStreaming.aspx 파일

<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="makeStreaming.aspx.cs" Inherits="WebApplication1.makeStreaming" %>

makeStreaming.aspx.cs 파일

using System;
using System.Collections.Generic;
using System.Web.UI;
using Newtonsoft.Json;

namespace WebApplication1
{
    public partial class makeStreaming : Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            // JSON 콘텐츠 타입 설정
            Response.ContentType = "application/json";

            // 미디어 아이템 생성
            var mediaItem = MakeItem();

            // JSON 데이터 생성
            string jsonData = JsonConvert.SerializeObject(mediaItem);

            // JSON 데이터 출력
            Response.Write(jsonData);
            Response.End();
        }

        private Dictionary<string, object> MakeItem()
        {
            // DRM 정보를 Dictionary로 설정
            var drm = new Dictionary<string, string>
            {
                { "appId", "APP ID를 넣어주세요" },
                { "userId", "USER ID를 넣어주세요" }
            };

            // 모바일 플레이어 재생 시 파일명 설정 (option)
            var metadata = new Dictionary<string, object>
            {
                { "title", "파일명" }
            };

            // 미디어 아이템을 Dictionary로 설정
            var item = new Dictionary<string, object>
            {
                { "url", "http://example.com/sample/sample.mp4.drm" },
                { "metadata", metadata },
                { "drm", drm }
            };

            return item;
        }
    }
}

2. Download 처리 부분

아래는 다운로드 영상을 재생하기 위한 JSON 객체를 생성하는 .NET ASP 코드 예시입니다.

이 코드는 .NET Framework 3.5 이상, C# 3.0 이상에서 지원하는 Newtonsoft.Json 라이브러리를 사용합니다.makeDownload.aspx 파일

<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="makeDownload.aspx.cs" Inherits="WebApplication1.makeDownload" %>

makeDownload.aspx.cs 파일

using System;
using System.Collections.Generic;
using System.Web.UI;
using Newtonsoft.Json;

namespace WebApplication1
{
    public partial class makeDownload : Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            // JSON 콘텐츠 타입 설정
            Response.ContentType = "application/json";

            // 미디어 아이템 생성
            var mediaItem = MakeItem();

            // JSON 데이터 생성
            string jsonData = JsonConvert.SerializeObject(mediaItem);

            // JSON 데이터 출력
            Response.Write(jsonData);
            Response.End();
        }

        private Dictionary<string, object> MakeItem()
        {
            // DRM 정보를 Dictionary로 설정
            var drm = new Dictionary<string, string>
            {
                { "appId", "APP ID를 넣어주세요" },
                { "userId", "USER ID를 넣어주세요" },
                { "offlineAccessPeriod", "86400" } // Download한 파일 offline 재생 허용 기간(초), undefined: 제한 없음, 0: offline 재생 불가
            };

            // 미디어 아이템을 Dictionary로 설정
            var metadata = new Dictionary<string, object>
            {
                { "downloadPath", "/타이틀/경로1/경로2" }
            };

            // 미디어 아이템을 Dictionary로 설정
            var item = new Dictionary<string, object>
            {
                { "url", "http://example.com/sample/sample.mp4.drm" },
                { "metadata", metadata },
                { "drm", drm }
            };

            return item;
        }
    }
}

위로 스크롤