public void UploadPiece(string key, int order, Stream stream) { var name = Guid.NewGuid() + ".m4a"; string filePath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, ConfigurationManager.AppSettings["PiecesPath"], name); if (!Directory.Exists(Directory.GetParent(filePath).FullName)) { Directory.GetParent(filePath).Create(); } using (var fileStream = File.Create(filePath)) { stream.CopyTo(fileStream); } var time = DateTime.Now; var piece = new AudioPiece(); piece.ExpirationTime = time.AddDays(3); piece.Key = key; piece.Order = order; piece.PhysicalFileName = filePath; piece.UploadTime = time; using (var context = new InnostarModelsContext()) { var repository = new AudioPieceRepository(context); repository._Insert(piece); repository._Save(); } }
public void PhonePutThrough() { //clear coroutine foreach (var coroutine in _phoneRelatedCoroutine) { CoroutineManager.StopCoroutine(coroutine); } _phoneRelatedCoroutine.Clear(); //plot mark targetPhoneCall?.OnCallPutThrough(); //change visual //TODO visual logic _ps.ChangeGameState("Phone_OnCall"); //start phone call audioclip if (targetPhoneCall != null) { _targetCallAudioPiece = new AudioPiece(targetPhoneCall.callContent, -1); } else { var audio = Services.audioManager.GetAudioClip("NoResponse", "PhoneCall/"); _targetCallAudioPiece = new AudioPiece(audio, -1); } _targetCallAudioPiece.onAudioFinished += () => { _ps.ChangeGameState(_previousPage); _previousPage = null; targetPhoneCall?.ChangePlotState(PlotManager.PlotState.Finished); targetPhoneCall = null; }; _targetCallAudioPiece.Play(); }
public void Hang() { //visually return if (!ReferenceEquals(_previousPage, null)) { _ps.ChangeGameState(_previousPage); _previousPage = null; } //if the phone hasn't put through yet, then it's broken if (_targetCallAudioPiece == null) { targetPhoneCall?.ChangePlotState(PlotManager.PlotState.Broke); targetPhoneCall = null; return; } else { //if(!_targetCallAudioPiece.audioSource.isPlaying) if (targetPhoneCall != null) { var timeRatio = _targetCallAudioPiece.audioSource.time / targetPhoneCall.callContent.length; if (timeRatio > 0.9f) { targetPhoneCall?.ChangePlotState(PlotManager.PlotState.Finished); } else { targetPhoneCall?.ChangePlotState(PlotManager.PlotState.Broke); } targetPhoneCall = null; } _targetCallAudioPiece.Stop(); _targetCallAudioPiece = null; } }