Android Open Source - Amphitheatre Stream Source






From Project

Back to project page Amphitheatre.

License

The source code is released under:

Apache License

If you think the Android project Amphitheatre listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.

Java Source Code

/*
 * Copyright (C) 2014 Michell Bak/*from w  w w . j a  va2 s.co  m*/
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package com.jerrellmardis.amphitheatre.server;

import com.jerrellmardis.amphitheatre.util.VideoUtils;

import java.io.IOException;
import java.io.InputStream;

import jcifs.smb.SmbException;
import jcifs.smb.SmbFile;
import jcifs.smb.SmbFileInputStreamOld;

public class StreamSource {

  protected String mime;
  protected long fp;
  protected long len;
  protected String name;
  protected SmbFile file;
  InputStream input;
  protected int bufferSize;

  public StreamSource(SmbFile file) throws SmbException{
    fp = 0;
    len = file.length();
    mime = VideoUtils.getMimeType(file.getName(), false);
    name = file.getName();
    this.file = file;
    bufferSize = 1024*32;
  }

  /**
   * You may notice a strange name for the smb input stream.
   * I made some modifications to the original one in the jcifs library for my needs,
   * but streaming required returning to the original one so I renamed it to "old".
   * However, I needed to specify a buffer size in the constructor. It looks now like this:
   * 
   *     public SmbFileInputStreamOld( SmbFile file, int readBuffer, int openFlags) throws SmbException, MalformedURLException, UnknownHostException {
                        this.file = file;
                        this.openFlags = SmbFile.O_RDONLY & 0xFFFF;
                        this.access = (openFlags >>> 16) & 0xFFFF;
                        if (file.type != SmbFile.TYPE_NAMED_PIPE) {
                            file.open( openFlags, access, SmbFile.ATTR_NORMAL, 0 );
                            this.openFlags &= ~(SmbFile.O_CREAT | SmbFile.O_TRUNC);
                        } else {
                            file.connect0();
                        }
                        readSize = readBuffer;
                        fs = file.length();
                    }
   * 
   * Setting buffer size by properties didn't work for me so I created this constructor.
   * In the libs folder there is a library modified by me. If you want to use a stock one, you
   * have to set somehow the buffer size to be equal with http server's buffer size which is 8192.
   * 
   * @throws java.io.IOException
   */

  public void open() throws IOException {
    try {
      input = new SmbFileInputStreamOld(file, bufferSize, 1);
      if(fp>0)
        input.skip(fp);
    } catch (Exception e) {
      throw new IOException(e);
    }
  }

  public int read(byte[] buff) throws IOException{
    return read(buff, 0, buff.length);
  }

  public int read(byte[] bytes, int start, int offs) throws IOException {
    int read =  input.read(bytes, start, offs);
    fp += read;
    return read;
  }

  public long moveTo(long position) throws IOException {
    fp = position;
    return fp;
  }

  public void close() {
    try {
      input.close();
    } catch (IOException e) {
      e.printStackTrace();
    }
  }

  public String getMimeType(){
    return mime;
  }

  public long length(){
    return len;
  }

  public String getName(){
    return name;
  }

  public long available(){
    return len - fp;
  }

  public void reset(){
    fp = 0;
  }

  public SmbFile getFile(){
    return file;
  }

  public int getBufferSize(){
    return bufferSize;
  }  
}




Java Source Code List

com.jerrellmardis.amphitheatre.activity.BootupActivity.java
com.jerrellmardis.amphitheatre.activity.BrowseActivity.java
com.jerrellmardis.amphitheatre.activity.DetailsActivity.java
com.jerrellmardis.amphitheatre.activity.GridViewActivity.java
com.jerrellmardis.amphitheatre.activity.SearchActivity.java
com.jerrellmardis.amphitheatre.api.ApiClient.java
com.jerrellmardis.amphitheatre.api.GuessItClient.java
com.jerrellmardis.amphitheatre.api.MediaClientFactory.java
com.jerrellmardis.amphitheatre.api.MediaClient.java
com.jerrellmardis.amphitheatre.api.TMDbClient.java
com.jerrellmardis.amphitheatre.api.TVDBClientTest.java
com.jerrellmardis.amphitheatre.api.TVDBClient.java
com.jerrellmardis.amphitheatre.api.TVDBService.java
com.jerrellmardis.amphitheatre.fragment.AddSourceDialogFragment.java
com.jerrellmardis.amphitheatre.fragment.BrowseFragment.java
com.jerrellmardis.amphitheatre.fragment.CustomizeDialogFragment.java
com.jerrellmardis.amphitheatre.fragment.SearchFragment.java
com.jerrellmardis.amphitheatre.fragment.VerticalGridFragment.java
com.jerrellmardis.amphitheatre.fragment.VideoDetailsFragment.java
com.jerrellmardis.amphitheatre.listeners.RowBuilderTaskListener.java
com.jerrellmardis.amphitheatre.listeners.TaskListener.java
com.jerrellmardis.amphitheatre.model.GridGenre.java
com.jerrellmardis.amphitheatre.model.Source.java
com.jerrellmardis.amphitheatre.model.VideoGroup.java
com.jerrellmardis.amphitheatre.model.Video.java
com.jerrellmardis.amphitheatre.model.guessit.Guess.java
com.jerrellmardis.amphitheatre.model.tmdb.Config.java
com.jerrellmardis.amphitheatre.model.tmdb.Episode.java
com.jerrellmardis.amphitheatre.model.tmdb.Genre.java
com.jerrellmardis.amphitheatre.model.tmdb.Movie.java
com.jerrellmardis.amphitheatre.model.tmdb.ProductionCompany.java
com.jerrellmardis.amphitheatre.model.tmdb.SearchResult.java
com.jerrellmardis.amphitheatre.model.tmdb.TvShow.java
com.jerrellmardis.amphitheatre.model.tmdb.Videos.java
com.jerrellmardis.amphitheatre.model.tvdb.BaseResponse.java
com.jerrellmardis.amphitheatre.model.tvdb.EpisodeResponse.java
com.jerrellmardis.amphitheatre.model.tvdb.Episode.java
com.jerrellmardis.amphitheatre.model.tvdb.Language.java
com.jerrellmardis.amphitheatre.model.tvdb.SeriesResult.java
com.jerrellmardis.amphitheatre.model.tvdb.Series.java
com.jerrellmardis.amphitheatre.server.StreamServer.java
com.jerrellmardis.amphitheatre.server.StreamSource.java
com.jerrellmardis.amphitheatre.server.Streamer.java
com.jerrellmardis.amphitheatre.service.LibraryUpdateService.java
com.jerrellmardis.amphitheatre.service.RecommendationsService.java
com.jerrellmardis.amphitheatre.task.DetailRowBuilderTask.java
com.jerrellmardis.amphitheatre.task.DownloadMovieTask.java
com.jerrellmardis.amphitheatre.task.DownloadTaskHelper.java
com.jerrellmardis.amphitheatre.task.DownloadTvShowTask.java
com.jerrellmardis.amphitheatre.task.DownloadVideoTask.java
com.jerrellmardis.amphitheatre.task.GetFilesTask.java
com.jerrellmardis.amphitheatre.task.NetworkSearchTask.java
com.jerrellmardis.amphitheatre.util.ApiConstants.java
com.jerrellmardis.amphitheatre.util.Base64.java
com.jerrellmardis.amphitheatre.util.BlurTransform.java
com.jerrellmardis.amphitheatre.util.Constants.java
com.jerrellmardis.amphitheatre.util.Enums.java
com.jerrellmardis.amphitheatre.util.PicassoBackgroundManagerTarget.java
com.jerrellmardis.amphitheatre.util.RecommendationBuilder.java
com.jerrellmardis.amphitheatre.util.SecurePreferences.java
com.jerrellmardis.amphitheatre.util.Utils.java
com.jerrellmardis.amphitheatre.util.VideoUtils.java
com.jerrellmardis.amphitheatre.widget.CardPresenter.java
com.jerrellmardis.amphitheatre.widget.DetailsDescriptionPresenter.java
com.jerrellmardis.amphitheatre.widget.GridItemPresenter.java
com.jerrellmardis.amphitheatre.widget.SeasonCardPresenter.java
com.jerrellmardis.amphitheatre.widget.SortedObjectAdapter.java
com.jerrellmardis.amphitheatre.widget.TvShowsCardPresenter.java