public void Play(int projectId)
        {
            var video = dispatcher.Dispatch(VideoActions.GetVideoForProject(projectId));

            Guard.This(video).AgainstDefaultValue("No video found for project");

            mp3Player = new Mp3AudioPlayer();
            mp3Player.Load(video.AudioFilePath);

            var appPreferences = dispatcher.Dispatch(AppPreferencesActions.GetAppPreferences());

            var startTime = DateTime.Now.AddMilliseconds(appPreferences.PlaybackBuffer);

            foreach (var devicePlayback in devicePlaybacks)
            {
                devicePlayback.Client.PlayVideo(devicePlayback.ProjectDeviceId,
                                                new Pi.Api.ApiRequests.PlayVideoRequest
                {
                    PlayAt           = startTime,
                    TimeReferenceUrl = string.Format("http://{0}:8001/api/time", GetTimeReferenceHost(devicePlayback.Client))
                });
            }

            while (DateTime.Now.CompareTo(startTime.AddMilliseconds(-20)) < 0)
            {
                continue;
            }

            mp3Player.Play();
        }
        public void LoadAudio(int projectId)
        {
            var video = dispatcher.Dispatch(VideoActions.GetVideoForProject(projectId));

            Guard.This(video).AgainstDefaultValue("Could not find video for project");

            if (audioTrack == null || audioTrack.AudioFilePath != video.FilePath)
            {
                audioTrack = AudioTrack.FromAudioFile(video.AudioFilePath);
            }
        }
Exemplo n.º 3
0
        public GlobalJsonResult <VideoMetadataResponse> GetProjectVideoMetadata(int projectId)
        {
            var video = dispatcher.Dispatch(VideoActions.GetVideoForProject(projectId));

            Guard.This(video).AgainstDefaultValue(string.Format("No video exists for project with id {0}", projectId));
            Guard.This(video.FilePath).WithRule(path => File.Exists(path), string.Format("Video {0} does not exist", video.FilePath));

            videoFileReader.Open(video.FilePath);
            var result = new VideoMetadataResponse();

            result.Populate(videoFileReader);

            return(GlobalJsonResult <VideoMetadataResponse> .Success(System.Net.HttpStatusCode.OK, result));
        }
Exemplo n.º 4
0
        public VideoMetadata StartReadingVideo(int projectId, int projectDeviceId)
        {
            var project = dispatcher.Dispatch(ProjectActions.GetProject(projectId));

            Guard.This(project).AgainstDefaultValue(string.Format("Could not find project with project id '{0}'", projectId));

            var video = dispatcher.Dispatch(VideoActions.GetVideoForProject(projectId));

            Guard.This(video).AgainstDefaultValue(string.Format("Could not find video for project '{0}' (id '{1}')", project.Name, project.Id));

            var projectDeviceVersion = dispatcher.Dispatch(ProjectDeviceActions.GetLatestProjectDeviceVersion(projectDeviceId));

            Guard.This(projectDeviceVersion).AgainstDefaultValue(string.Format("Could not get latest project device version for project '{0}' (id '{1}')", project.Name, project.Id));

            reader = videoFileReader();
            reader.Open(video.FilePath);

            framesRead                = 0;
            framesToRead              = reader.FrameCount;
            this.videoReference       = video;
            this.projectDeviceVersion = projectDeviceVersion;

            return(new VideoMetadata(reader.FrameCount, reader.FrameRate));
        }
Exemplo n.º 5
0
        public void ProcessProjectDeviceVersion(BackgroundJob job)
        {
            var projectDeviceVersion = dispatcher.Dispatch(ProjectDeviceActions.GetProjectDeviceVersion(job.ProjectDeviceVersionId));

            Guard.This(projectDeviceVersion).AgainstDefaultValue(string.Format("Could not find project device version '{0}'", job.ProjectDeviceVersionId));

            var device = dispatcher.Dispatch(DeviceActions.GetProjectDevice(projectDeviceVersion.ProjectDeviceId));

            Guard.This(device).AgainstDefaultValue(string.Format("Could not find project device with project device Id '{0}'", projectDeviceVersion.ProjectDeviceId));
            Guard.This(device).WithRule(d => deviceStatusService.IsOnline(device), string.Format("Device {0} (with IP Address {1}) is not online", device.Name, device.IpAddress));

            var project = dispatcher.Dispatch(ProjectActions.GetProjectFromProjectDevice(projectDeviceVersion.ProjectDeviceId));

            Guard.This(project).AgainstDefaultValue(string.Format("Could not find project from project device with id '{0}'", projectDeviceVersion.ProjectDeviceId));

            var video = dispatcher.Dispatch(VideoActions.GetVideoForProject(project.Id));

            Guard.This(video).AgainstDefaultValue(string.Format("Could not find video for project '{0}'", project.Name));

            using (var videoProcessor = videoProcessorInstantiator())
            {
                var videoMetadata = videoProcessor.StartReadingVideo(project.Id, projectDeviceVersion.ProjectDeviceId);
                var client        = piClientFactory.ForDevice(device);

                // Update video metadata (use project device id instead of video id with client (could have the same video in multiple configurations)
                var existingVideosOnPi = client.GetAllVideoMetadata();
                var existingVideoOnPi  = existingVideosOnPi.SingleOrDefault(v => v.Id == projectDeviceVersion.ProjectDeviceId);

                if (existingVideoOnPi == null)
                {
                    client.CreateVideoMetadata(new VideoMetadataCreateRequest
                    {
                        Id        = projectDeviceVersion.ProjectDeviceId,
                        FileName  = video.FilePath,
                        FrameRate = videoMetadata.FrameRate
                    });
                }
                else
                {
                    client.UpdateVideoMetadata(new VideoMetadataPutRequest
                    {
                        Id        = projectDeviceVersion.ProjectDeviceId,
                        FileName  = video.FilePath,
                        FrameRate = videoMetadata.FrameRate,
                    });
                }

                // Clear, then send frames to Pi
                client.ClearFrames(projectDeviceVersion.ProjectDeviceId);

                int framePosition = 1;
                while (true)
                {
                    var read = videoProcessor.ReadNext1000Frames();
                    client.SendFrames(projectDeviceVersion.ProjectDeviceId, new AppendFramesRequest
                    {
                        AppendFrameRequests = read.Frames
                                              .Select(f => new AppendFrameRequest {
                            BinaryData = f, Position = framePosition
                        })
                                              .ToArray()
                    });

                    dispatcher.Dispatch(BackgroundJobActions.MarkPercentageCompletion(job.Id, read.PercentageComplete));

                    if (!read.MoreFrames)
                    {
                        break;
                    }

                    framePosition++;
                }
            }
        }
Exemplo n.º 6
0
        public GlobalJsonResult <VideoReference> GetProjectVideo(int projectId)
        {
            var result = dispatcher.Dispatch(VideoActions.GetVideoForProject(projectId));

            return(GlobalJsonResult <VideoReference> .Success(System.Net.HttpStatusCode.OK, result));
        }