예제 #1
0
        /// <summary>
        /// 推流的地址
        /// </summary>
        /// <param name="streamname">直播流的名称</param>
        public string GetPublish(string streamname)
        {
            pili_sdk.pili.Stream stream = Pili.API <IStream>().GetForTitle(streamname);
            if (stream == null)
            {
                return(string.Empty);
            }
            string url = string.Format("https://{0}/{1}/{2}", stream.PublishRtmpHost, stream.HubName, stream.Title);

            return(url);
        }
예제 #2
0
        /// <summary>
        /// 创建直播流
        /// </summary>
        /// <param name="name"></param>
        public pili_sdk.pili.Stream StreamCreat(string name)
        {
            Stream stream = null;

            try
            {
                stream = Pili.API <IStream>().Create(name);
                return(stream);
            }
            catch (Exception e)
            {
                throw e;
            }
        }
예제 #3
0
        /// <summary>
        /// 教师的直播章节
        /// </summary>
        /// <param name="thid">教师id</param>
        /// <param name="couid">课程id</param>
        /// <returns>返回内容包括:带直播的章节的名称、ID、UID、课程名称、直播相关信息;
        /// LivePublish:直播推流地址,示例 rtmp://pili-publish.zhibo.weisha100.cn/ceshi5/132_267_548f3efe842b564c74babb4c70fc
        /// LiveHLS:播放地址,示例 http://pili-live-hls.zhibo.weisha100.cn/ceshi5/132_267_548f3efe842b564c74babb4c70fc
        /// LiveCover:直播封面,每五秒更新,示例http://pili-snapshot.zhibo.weisha100.cn/ceshi5/132_267_548f3efe842b564c74babb4c70fc
        /// LiveTime:直播开始时间,这个时间仅供于通知学员何时开始,从技术来说直播可以随时开始
        /// LiveSpan:直播课的时长,仅供告知学员课时长度,从技术上来说直播不受时长限制
        /// </returns>
        /// <remarks></remarks>
        public Outline_LiveInfo[] Lives(int thid, int couid)
        {
            Song.Entities.Course cour = Business.Do <ICourse>().CourseSingle(couid);
            if (cour == null)
            {
                return(null);
            }
            if (cour.Th_ID != thid)
            {
                return(null);
            }
            //
            Song.Entities.Outline[] outls = Business.Do <IOutline>().OutlineCount(couid, true, null, true, 0);
            List <Outline_LiveInfo> list  = new List <Outline_LiveInfo>();
            //直播截图的域名
            string snapshot = Business.Do <ILive>().GetSnapshot;
            string proto    = Business.Do <ILive>().GetProtocol; //协议,http还是https

            foreach (Song.Entities.Outline o in outls)
            {
                pili_sdk.pili.Stream stream = Pili.API <IStream>().GetForTitle(o.Ol_LiveID);
                if (stream == null)
                {
                    continue;
                }
                //推流地址
                string publist = string.Format("rtmp://{0}/{1}/{2}", stream.PublishRtmpHost, stream.HubName, stream.Title);
                //播放地址
                string play = string.Format("{0}://{1}/{2}/{3}.m3u8", proto, stream.LiveHlsHost, stream.HubName, stream.Title);
                //封面地址
                string cover = string.Format("http://{0}/{1}/{2}.jpg", snapshot, stream.HubName, stream.Title);
                list.Add(new Outline_LiveInfo()
                {
                    Name        = o.Ol_Name,
                    ID          = o.Ol_ID,
                    UID         = o.Ol_UID,
                    Course      = cour.Cou_Name,
                    LiveID      = stream.StreamID,
                    LiveTitle   = stream.Title,
                    LiveTime    = o.Ol_LiveTime,
                    LiveSpan    = o.Ol_LiveSpan,
                    LivePublish = publist,
                    LiveHLS     = play,
                    LiveCover   = cover
                });
            }
            return(list.ToArray <Outline_LiveInfo>());
        }
예제 #4
0
        /// <summary>
        /// 直播流列表
        /// </summary>
        /// <param name="prefix">直播流名称前缀</param>
        /// <param name="living">是否正在直播中</param>
        /// <param name="count">取几条记录</param>
        /// <returns></returns>
        public pili_sdk.pili.StreamList StreamList(string prefix, bool?living, long count)
        {
            string marker      = null;   // optional
            long   limit       = count;  // optional
            string titlePrefix = prefix; // optional

            try
            {
                StreamList     streamList = Pili.API <IStream>().List(marker, limit, titlePrefix, living);
                IList <Stream> list       = streamList.Streams;
                foreach (Stream s in list)
                {
                    // access the stream
                }
                return(streamList);
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
예제 #5
0
        /// <summary>
        /// 删除直播流
        /// </summary>
        /// <param name="name"></param>
        /// <returns></returns>
        public bool StreamDelete(string name)
        {
            Stream stream = this.StreamGet(name);

            if (stream == null)
            {
                return(false);
            }
            //
            try
            {
                string res = Pili.API <IStream>().Delete(stream);
                if ("No Content".Equals(res))
                {
                    return(true);
                }
                return(false);
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
예제 #6
0
        /// <summary>
        /// 章节的状态
        /// </summary>
        /// <param name="olid"></param>
        /// <returns></returns>
        public Dictionary <string, object> State(int olid)
        {
            Dictionary <string, object> dic = new Dictionary <string, object>();

            Song.Entities.Accounts acc = Extend.LoginState.Accounts.CurrentUser;
            dic.Add("isLogin", acc != null);    //学员是否登录
            //
            Song.Entities.Outline outline = Business.Do <IOutline>().OutlineSingle(olid);
            if (outline == null)
            {
                throw new Exception("章节不存在");
            }
            dic.Add("Name", outline.Ol_Name);
            Song.Entities.Course course = Business.Do <ICourse>().CourseSingle(outline.Cou_ID);
            if (course == null)
            {
                throw new Exception("课程不存在");
            }
            dic.Add("Course", course.Cou_Name);
            Song.Entities.Organization orgin;
            //是否限制在桌面应用中打开
            dic.Add("DeskAllow", this.getDeskallow(course, outline, out orgin));
            //是否在切换浏览器时继续播放
            dic.Add("SwitchPlay", this.getSwitchPlay(course, acc, orgin));
            //是否免费,或是限时免费
            if (course.Cou_IsLimitFree)
            {
                DateTime freeEnd = course.Cou_FreeEnd.AddDays(1).Date;
                if (!(course.Cou_FreeStart <= DateTime.Now && freeEnd >= DateTime.Now))
                {
                    course.Cou_IsLimitFree = false;
                }
            }
            //是否可以学习,是否购买
            bool isStudy = false, isBuy = false, canStudy = false;

            if (acc != null)
            {
                isStudy = Business.Do <ICourse>().Study(course.Cou_ID, acc.Ac_ID);
                isBuy   = course.Cou_IsFree || course.Cou_IsLimitFree ? true : Business.Do <ICourse>().IsBuy(course.Cou_ID, acc.Ac_ID);
                //学习记录
                Song.Entities.LogForStudentStudy studyLog = Business.Do <IStudent>().LogForStudySingle(acc.Ac_ID, outline.Ol_ID);
                dic.Add("StudyTime", studyLog != null ? studyLog.Lss_StudyTime : 0);
                dic.Add("PlayTime", studyLog != null ? studyLog.Lss_PlayTime : 0);
            }
            dic.Add("isStudy", isStudy);
            dic.Add("isBuy", isBuy);
            //是否可以学习,如果是免费或已经选修便可以学习,否则当前课程允许试用且当前章节是免费的,也可以学习
            canStudy = isBuy || (isStudy && outline.Ol_IsUse && outline.Ol_IsFinish && course.Cou_IsTry && outline.Ol_IsFree);
            dic.Add("canStudy", canStudy);
            //是否有知识库
            int knlCount = Business.Do <IKnowledge>().KnowledgeOfCount(-1, course.Cou_ID, -1, true);

            dic.Add("isKnl", knlCount > 0 && canStudy);

            //是否有视频,是否为外链视频

            List <Song.Entities.Accessory> videos = Business.Do <IAccessory>().GetAll(outline.Ol_UID, "CourseVideo");
            bool existVideo = videos.Count > 0;

            dic.Add("outerVideo", existVideo && (videos.Count > 0 && videos[0].As_IsOuter));    //站外视频,包括其它网站的视频,或是视频播放链接
            dic.Add("otherVideo", existVideo && (videos.Count > 0 && videos[0].As_IsOther));    //其它视频平台的链接
            if (videos.Count > 0)
            {
                string videoUrl = existVideo ? videos[0].As_FileName : string.Empty; //视频地址
                //如果是内部链接
                if (existVideo && !videos[0].As_IsOuter)
                {
                    videoUrl = Upload.Get[videos[0].As_Type].Virtual + videoUrl;
                    string ext = System.IO.Path.GetExtension(videoUrl).ToLower();
                    if (ext == ".flv")
                    {
                        videoUrl = Path.ChangeExtension(videoUrl, ".mp4");
                    }
                }
                dic.Add("urlVideo", canStudy ? videoUrl : string.Empty);
                outline.Ol_IsLive = false;
            }
            //直播
            bool isLive = outline.Ol_IsLive, isLiving = false;

            if (outline.Ol_IsLive)
            {
                string urlVideo = string.Empty;
                if (canStudy)
                {
                    //查询直播状态
                    pili_sdk.pili.StreamStatus status = Pili.API <IStream>().Status(outline.Ol_LiveID);
                    if (status != null)
                    {
                        pili_sdk.pili.Stream stream = status.Stream;
                        string proto = Business.Do <ILive>().GetProtocol; //协议,http还是https
                        urlVideo   = string.Format("{0}://{1}/{2}/{3}.m3u8", proto, stream.LiveHlsHost, stream.HubName, stream.Title);
                        isLiving   = status.Status == "connected";        //正在直播
                        existVideo = isLiving ? false : existVideo;
                    }
                }
                //直播播放地址
                if (!dic.ContainsKey("urlVideo"))
                {
                    dic.Add("urlVideo", urlVideo);
                }
                //直播开始或结束
                dic.Add("LiveStart", DateTime.Now > outline.Ol_LiveTime);
                dic.Add("LiveOver", outline.Ol_LiveTime.AddMinutes(outline.Ol_LiveSpan) < DateTime.Now);
            }
            dic.Add("isLive", outline.Ol_IsLive);      //是否为直播章节
            dic.Add("isLiving", isLiving && canStudy); //是否在直播中
            dic.Add("existVideo", existVideo && canStudy);

            //是否有课程内容
            bool isContext = !string.IsNullOrWhiteSpace(outline.Ol_Intro);

            dic.Add("isContext", isContext && canStudy);
            //是否有试题
            bool isQues = Business.Do <IOutline>().OutlineIsQues(outline.Ol_ID, true);

            dic.Add("isQues", isQues && canStudy);
            //是否有附件
            int accessCount = Business.Do <IAccessory>().OfCount(outline.Ol_UID, "Course");

            dic.Add("isAccess", accessCount > 0 && canStudy);
            //啥都没有(视频,内容,附件,试题,都没有)
            bool isNull = !(existVideo || isLive || isContext || isQues || isQues || accessCount > 0);

            dic.Add("isNull", isNull || !canStudy);
            return(dic);
        }
예제 #7
0
 /// <summary>
 /// 获取直播流
 /// </summary>
 /// <param name="name"></param>
 /// <returns></returns>
 public pili_sdk.pili.Stream StreamGet(string name)
 {
     return(Pili.API <IStream>().GetForTitle(name));
 }
예제 #8
0
 public bool Test(string accesskey, string secretkey, string hubname)
 {
     return(Pili.API <IStream>().Test(accesskey, secretkey, hubname, "v1"));
 }