public WebMovingPicture GetMovingPicture(int id) { WebMovingPicture pic = new WebMovingPicture(); DBLocations dbs = Utils.GetMPDbLocations(); SQLiteConnection db = new SQLiteConnection(SQLiteConnStr(dbs.db_movingpictures)); try { db.Open(); } catch (Exception) { return(pic); } SQLiteCommand cmd = db.CreateCommand(); cmd.CommandText = "SELECT local_media.id,title,summary,fullpath,genres,certification,year FROM local_media,local_media__movie_info,movie_info WHERE local_media.id=local_media__movie_info.local_media_id AND local_media__movie_info.movie_info_id=movie_info.id AND local_media.id=" + id.ToString(); SQLiteDataReader reader = cmd.ExecuteReader(); if (reader.Read()) { pic = new WebMovingPicture(SafeInt32(reader, 0), SafeStr(reader, 1), SafeStr(reader, 2), SafeStr(reader, 3), SafeStr(reader, 4), SafeStr(reader, 5), SafeInt32(reader, 6)); } reader.Close(); reader.Dispose(); cmd.Dispose(); db.Close(); db.Dispose(); return(pic); }
protected void Page_Load(object sender, EventArgs e) { string filename = ""; List <EncoderConfig> cfgs = Utils.LoadConfig(); EncoderConfig cfg = cfgs[Int32.Parse(Request.QueryString["idProfile"])]; ServiceInterface server = new ServiceInterface(); if (Request.QueryString["idChannel"] != null) { if (server.GetChannel(Int32.Parse(Request.QueryString["idChannel"])).isRadio) { bufferSize = 2560; } WebTvResult res = server.StartTimeShifting(Int32.Parse(Request.QueryString["idChannel"])); if (res.result != 0) { Utils.Log("Streamer.aspx: ERROR: StartTimeShifting failed with error: " + res.result.ToString()); Response.Output.WriteLine("ERROR: StartTimeShifting failed with error: " + res.result.ToString()); Response.End(); return; } usedCard = res.user.idCard; usedChannel = res.user.idChannel; tvServerUsername = res.user.name; if (cfg.inputMethod == TransportMethod.Filename) { filename = res.rtspURL; } else { filename = res.timeshiftFile; } } else if (Request.QueryString["idRecording"] != null) { WebRecording rec = server.GetRecording(Int32.Parse(Request.QueryString["idRecording"])); filename = rec.fileName; } else if (Request.QueryString["idMovie"] != null) { WebMovie movie = server.GetMovie(Int32.Parse(Request.QueryString["idMovie"])); filename = movie.file; } else if (Request.QueryString["idMusicTrack"] != null) { WebMusicTrack track = server.GetMusicTrack(Int32.Parse(Request.QueryString["idMusicTrack"])); filename = track.file; } else if (Request.QueryString["idTvSeries"] != null) { WebSeries series = server.GetTvSeries(Request.QueryString["idTvSeries"]); filename = series.filename; } else if (Request.QueryString["idMovingPicture"] != null) { WebMovingPicture pic = server.GetMovingPicture(Int32.Parse(Request.QueryString["idMovingPicture"])); filename = pic.filename; } if (!File.Exists(filename) && !filename.StartsWith("rtsp://")) { Utils.Log("Streamer.aspx: Requested file " + filename + " does not exist."); return; } Response.Clear(); Response.Buffer = false; Response.BufferOutput = false; Response.AppendHeader("Connection", "Keep-Alive"); Response.ContentType = "video/x-msvideo"; Response.StatusCode = 200; Stream mediaStream = null; EncoderWrapper encoder = null; Stream outStream = null; if (cfg.inputMethod != TransportMethod.Filename) { if (Request.QueryString["idChannel"] != null) { mediaStream = new TsBuffer(filename); } else { mediaStream = new FileStream(filename, FileMode.Open, FileAccess.Read, FileShare.ReadWrite); } encoder = new EncoderWrapper(mediaStream, cfg); } else { encoder = new EncoderWrapper(filename, cfg); } if (cfg.useTranscoding) { outStream = encoder; } else { outStream = mediaStream; } byte[] buffer = new byte[bufferSize]; int read; try { while ((read = outStream.Read(buffer, 0, buffer.Length)) > 0) { try { Response.OutputStream.Write(buffer, 0, read); } catch (Exception) { break; // stream is closed } if (Request.QueryString["idChannel"] != null) { server.SendHeartBeat(usedChannel, usedCard, tvServerUsername); } } } catch (Exception ex) { Utils.Log("Streamer.aspx: Exception raised=" + ex.Message + Environment.NewLine + ex.StackTrace); } if (mediaStream != null) { mediaStream.Close(); } if (Request.QueryString["idChannel"] != null) { server.StopTimeShifting(usedChannel, usedCard, tvServerUsername); } encoder.StopProcess(); Response.End(); }