Android Open Source - streaming_project Media






From Project

Back to project page streaming_project.

License

The source code is released under:

GNU General Public License

If you think the Android project streaming_project 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

package com.example.streaming.streaming;
//from  w  w w .  j  ava 2s  .co m

import org.json.JSONException;
import org.json.JSONObject;

import java.util.Date;


// This is the Streaming App's model layer. It represents a media file which can be a video or audio
// file.
// TODO: make Media the parent class and Movie and Song its children
public class Media {
    // Data that represents a media file. This data will be stored in a SQLite database
    // TODO: we should also display the media type, e.g. ogg, mp3 or h.264
    // TODO: Add the year that the the media was produced by the company
    // TODO: date should be called timestamp. year is when the media was produced
    private static final String JSON_MEDIA_ID = "media_id";
    private static final String JSON_FILENAME = "filename";
    private static final String JSON_TITLE = "title";
    private static final String JSON_ARTIST = "artist";
    private static final String JSON_ALBUM = "album"; // TODO: it is not send by the server
    private static final String JSON_LENGTH = "length";
    private static final String JSON_ENCODER = "encoder";
    private static final String JSON_BITRATE = "bitrate";
    private static final String JSON_SAMPLE_RATE = "sample_rate";
    private static final String JSON_LAYER = "layer";
    private static final String JSON_DATE = "date"; // TODO: not used
    private static final String JSON_YEAR = "year"; // TODO: neither this one
    private static final String JSON_PHOTO = "photo"; // TODO: nor this one

    // TODO: if the media is of ogg type, then some info are not relevant such as bitrate (always 0) and layer
    private int mMediaId;
    private String mFilename;
    private String mTitle;
    private String mArtist;
    private String mAlbum;
    private double mLength; // in seconds
    private int mMins;
    private int mSecs;
    private String mEncoder; // TODO: use better data types for some of the attributes
    private int mBitrate;
    private int mSampleRate;
    private int mLayer;
    private Date mYear;
    private Date mDate;
    //private Photo mPhoto; // TODO: not used

    public int getMediaId() {
        return mMediaId;
    }

    public void setMediaId(int mediaId) {
        mMediaId = mediaId;
    }

    public int getMins() {
        return mMins;
    }

    public void setMins(int mins) {
        mMins = mins;
    }

    public int getSecs() {
        return mSecs;
    }

    public void setSecs(int secs) {
        mSecs = secs;
    }

    public double getLength() {
        return mLength;
    }

    public void setLength(double length) {
        mLength = length;
    }

    public String getFilename() {
        return mFilename;
    }

    public void setFilename(String filename) {
        mFilename = filename;
    }

    // TODO: this method is not called anywhere, check that it is the case
    public Media() {
        mDate = new Date();
        //Calendar calendar = Calendar.getInstance();
        //calendar.setTime(mDate);
    }

    // Constructor that accepts a JSONObject
    // NOTE: it is called in MediaManager.insertMedia(JSONObject) as we are processing each JSON
    // object representing a media file
    public Media(JSONObject json) throws JSONException {
        // TODO: Check that everything is extracted from the JSON object and organize better the various ifs
        if (json.has(JSON_MEDIA_ID)) {
            mMediaId = json.getInt(JSON_MEDIA_ID);
        }
        if (json.has(JSON_TITLE)) {
            mTitle = json.getString(JSON_TITLE);
        }
        // TODO: There is no Date yet in the JSON object that the server sends us
        if (json.has(JSON_DATE)) {
            mDate = new Date(json.getLong(JSON_DATE));
        } else {
            // TODO: for the moment, we are giving the current date for mDate
            mDate = new Date();
            // TODO: what is the point of doing what follows?
            //Calendar calendar = Calendar.getInstance();
            //calendar.setTime(mDate);
        }
        if (json.has(JSON_FILENAME))
            mFilename = json.getString(JSON_FILENAME);
        if (json.has(JSON_ARTIST))
            mArtist = json.getString(JSON_ARTIST);
        if (json.has(JSON_ALBUM))
            mAlbum = json.getString(JSON_ALBUM);
        if (json.has(JSON_LENGTH))
            mLength = json.getDouble(JSON_LENGTH);
            // Convert the media length (which is in seconds) in a more human-readable format: mm:ss
            // TODO: check if there is a better way to do this conversion (e.g. built-in functions in java)
            mMins = (int) mLength / 60;
            mSecs = (int) mLength % 60;
        if (json.has(JSON_ENCODER))
            mEncoder = json.getString(JSON_ENCODER);
        if (json.has(JSON_BITRATE))
            mBitrate = json.getInt(JSON_BITRATE);
        if (json.has(JSON_SAMPLE_RATE))
            mSampleRate = json.getInt(JSON_SAMPLE_RATE);
        if (json.has(JSON_LAYER))
            mLayer = json.getInt(JSON_LAYER);
        // TODO: no photo yet
        //if (json.has(JSON_PHOTO))
            //mPhoto = new Photo(json.getJSONObject(JSON_PHOTO));
        if (json.has(JSON_YEAR))
            mYear = new Date(json.getLong(JSON_YEAR));
    }

    @Override
    // ArrayAdapter<T>.getView() calls toString() on a Media object to populate the TextView
    // NOTE: ArrayAdapter<T>.getView() is called by ListView (from MediaListFragment)
    public String toString() {
        return mTitle;
    }

    public String getTitle() {
        return mTitle;
    }

    public void setTitle(String title) {
        mTitle = title;
    }

    public String getArtist() {
        return mArtist;
    }

    public void setArtist(String artist) {
        mArtist = artist;
    }

    public String getEncoder() {
        return mEncoder;
    }

    public void setEncoder(String encoder) {
        mEncoder = encoder;
    }

    public int getBitrate() {
        return mBitrate;
    }

    public void setBitrate(int bitrate) {
        mBitrate = bitrate;
    }

    public int getSampleRate() {
        return mSampleRate;
    }

    public void setSampleRate(int sampleRate) {
        mSampleRate = sampleRate;
    }

    public int getLayer() {
        return mLayer;
    }

    public void setLayer(int layer) {
        mLayer = layer;
    }

    public String getAlbum() {
        return mAlbum;
    }

    public void setAlbum(String album) {
        mAlbum = album;
    }

    public Date getYear() {
        return mYear;
    }

    public void setYear(Date year) {
        mYear = year;
    }

    public Date getDate() {
        return mDate;
    }

    public void setDate(Date date) {
        mDate = date;
    }

    /*
    public Photo getPhoto() {
        return mPhoto;
    }

    public void setPhoto(Photo photo) {
        mPhoto = photo;
    }*/
}




Java Source Code List

com.example.streaming.streaming.ApplicationTest.java
com.example.streaming.streaming.AssetsPropertyReader.java
com.example.streaming.streaming.DataFetcher.java
com.example.streaming.streaming.DataLoader.java
com.example.streaming.streaming.MainActivity.java
com.example.streaming.streaming.MediaActivity.java
com.example.streaming.streaming.MediaDatabaseHelper.java
com.example.streaming.streaming.MediaFragment.java
com.example.streaming.streaming.MediaListActivity.java
com.example.streaming.streaming.MediaListFragment.java
com.example.streaming.streaming.MediaLoader.java
com.example.streaming.streaming.MediaManager.java
com.example.streaming.streaming.MediaProvider.java
com.example.streaming.streaming.Media.java
com.example.streaming.streaming.SQLiteCursorLoader.java
com.example.streaming.streaming.SingleFragmentActivity.java