コード例 #1
0
        public ActionResult Create(MediaElement mediaelement)
        {
            if (ModelState.IsValid)
            {
                mediaelement.UserId = User.Identity.Name;
                db.MediaElements.Add(mediaelement);
                db.SaveChanges();
                return RedirectToAction("Index");
            }

            return View(mediaelement);
        }
コード例 #2
0
 public JsonResult Save(MediaElement mediaelement)
 {
     try
     {
         mediaelement.UserId = User.Identity.Name;
         mediaelement.FileUrl = GetStreamingUrl(mediaelement.AssetId);
         db.MediaElements.Add(mediaelement);
         db.SaveChanges();
         return Json(new { Saved = true, StreamingUrl =  mediaelement.FileUrl});
     }
     catch (Exception ex)
     {
         return Json(new { Saved = false });
     }
 }
コード例 #3
0
 public ActionResult Edit(MediaElement mediaelement)
 {
     if (ModelState.IsValid)
     {
         db.Entry(mediaelement).State = EntityState.Modified;
         db.SaveChanges();
         return RedirectToAction("Index");
     }
     return View(mediaelement);
 }
 private void SaveNewAssetToDatabase(MediaElement element, string newAssetName, string userName, IAsset preparedAsset)
 {
     var hub = GlobalHost.ConnectionManager.GetHubContext<JobStatusHub>();
     hub.Clients.All.updateJobStatus(element.AssetId, "Done");
     AzureMediaPortalContext dbContext = new AzureMediaPortalContext();
     MediaElement newMedia = new MediaElement
     {
         UserId = userName,
         EncodingType = element.EncodingType,
         Title = newAssetName,
         AssetId = preparedAsset.Id,
         FileUrl = GetStreamingUrl(preparedAsset.Id)
     };
     dbContext.MediaElements.Add(newMedia);
     dbContext.SaveChanges();
     hub.Clients.All.updateJobCompleted(element.AssetId, "Newly Encoded asset is now listed.");
 }
        public JsonResult Encode(MediaElement element)
        {
            string serviceName = ConfigurationManager.AppSettings["MediaAccountName"];
            string serviceKey = ConfigurationManager.AppSettings["MediaAccountKey"];
            var context = new CloudMediaContext(serviceName, serviceKey); //#1
            var encodeAssetId = element.AssetId;
            // Preset reference documentation: http://msdn.microsoft.com/en-us/library/windowsazure/jj129582.aspx
            var encodingPreset = element.EncodingType; 
            var assetToEncode = context.Assets.Where(a => a.Id == encodeAssetId).FirstOrDefault();
            if (assetToEncode == null)
            {
                throw new ArgumentException("Could not find assetId: " + encodeAssetId);
            }
            IJob job = context.Jobs.Create("Encoding " + assetToEncode.Name + " to " + encodingPreset); //#2
            IMediaProcessor latestWameMediaProcessor = (from p in context.MediaProcessors 
                                                        where p.Name == "Windows Azure Media Encoder" 
                                                        select p).ToList().OrderBy(wame => 
                                                            new Version(wame.Version)).LastOrDefault(); //#3
            ITask encodeTask = job.Tasks.AddNew("Encoding", latestWameMediaProcessor, encodingPreset, TaskOptions.None); //#4
            encodeTask.InputAssets.Add(assetToEncode); //#5
            string newAssetName = assetToEncode.Name + " as " + encodingPreset;
            string userName = User.Identity.Name;
            encodeTask.OutputAssets.AddNew(newAssetName, AssetCreationOptions.None); //#6

            job.StateChanged += job_StateChanged; //#7
            job.Submit(); //#8
            job.GetExecutionProgressTask(CancellationToken.None).ContinueWith(t =>
            {
                if (t.IsCompleted) 
                {
                    var preparedAsset = PublishAsset(job); //#9
                    SaveNewAssetToDatabase(element, newAssetName, userName, preparedAsset); //#10
                }
            });
            return Json(new { status = "Starting" });
        }