Skip to content

Commit

Permalink
MP3 Parser
Browse files Browse the repository at this point in the history
  • Loading branch information
LogAnd1 committed Jan 9, 2018
1 parent f4938da commit 5210ca2
Show file tree
Hide file tree
Showing 10 changed files with 218 additions and 3 deletions.
6 changes: 6 additions & 0 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.pp.podcastplayer">

<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.READ_PHONE_STATE" />

<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
Expand All @@ -27,6 +29,10 @@
android:name=".AddActivity"
android:label="@string/title_activity_download"
android:theme="@style/AppTheme.NoActionBar" />
<activity
android:name=".PodcastList"
android:label="@string/title_activity_podcast_list"
android:theme="@style/AppTheme.NoActionBar"></activity>
</application>

</manifest>
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ public List<DataRSS> parseData(InputStream inputStream) throws XmlPullParserExce
IOException {
String naslov = "";
String mp3 = "";
String opis = "";
boolean itemObj = false;
Expand Down
18 changes: 18 additions & 0 deletions app/src/main/java/com/example/pp/podcastplayer/DataRSSmp3.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package com.example.pp.podcastplayer;

/**
* Created by Logar on 28.12.2017.
*/

public class DataRSSmp3 {

public String naslov;
public String mp3;
public String opis;

public DataRSSmp3(String naslov, String mp3, String opis) {
this.naslov = naslov;
this.mp3 = mp3;
this.opis = opis;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,6 @@ public void loadStart() {
NavigationView navigationView = (NavigationView) findViewById(R.id.nav_view);
navigationView.setNavigationItemSelectedListener(this);


}

@Override
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.example.pp.podcastplayer;

import android.content.Intent;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.net.Uri;
Expand Down Expand Up @@ -39,7 +40,9 @@ public DataObjectHolder(View itemView) {

@Override
public void onClick(View v) {
myClickListener.onItemClick(getAdapterPosition(), v);
// myClickListener.onItemClick(getAdapterPosition(), v);
Intent intent = new Intent(v.getContext(), PodcastList.class);
v.getContext().startActivity(intent);
}
}

Expand Down
122 changes: 122 additions & 0 deletions app/src/main/java/com/example/pp/podcastplayer/ParserMP3.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,122 @@
package com.example.pp.podcastplayer;

import android.util.Xml;

import org.xmlpull.v1.XmlPullParser;
import org.xmlpull.v1.XmlPullParserException;

import java.io.IOException;
import java.io.InputStream;
import java.util.ArrayList;
import java.util.List;

/**
* Created by Logar on 28.12.2017.
*/

public class ParserMP3 {

DataRSSmp3 data;
String urlRSS;


// Razclenjevanje podatkov
public DataRSSmp3 parseData(InputStream inputStream) throws XmlPullParserException,
IOException {

String naslov = null;
String mp3 = null;
String opis = null;

boolean itemObj = false;
DataRSSmp3 item = new DataRSSmp3(naslov,mp3,opis);


List<DataRSS> items = new ArrayList<>();

try {
// Uporabimo xmlPullParser
XmlPullParser xmlPullParser = Xml.newPullParser();
xmlPullParser.setFeature(XmlPullParser.FEATURE_PROCESS_NAMESPACES, false);
xmlPullParser.setInput(inputStream, null);

// Pregledujemo znacke do konca dokumenta
xmlPullParser.nextTag();
while (xmlPullParser.next() != XmlPullParser.END_DOCUMENT) {
// prebermo tip dogodka (zacetek dokumenta, konec)
int event = xmlPullParser.getEventType();

// Preberemo ime znacke (item)
String tagName = xmlPullParser.getName();

if( tagName == null ) {
continue;
}

// Zacetek dokumenta
if (event == XmlPullParser.START_TAG) {
if(tagName.equalsIgnoreCase("item")) {
itemObj = true;
continue;
}
}

// Konec dokumenta
if(event == XmlPullParser.END_TAG) {
if(tagName.equalsIgnoreCase("item")) {
itemObj = false;
}
continue;
}


// Log.d("MyXmlParser", "Parsing name ==> " + name);
String res = "";


if (xmlPullParser.next() == XmlPullParser.TEXT) {
res = xmlPullParser.getText();
xmlPullParser.nextTag();
}

// Pridobivanje podatkov iz znack

switch (tagName){
case "title":
//Log.d("Add", res);
naslov = res;

break;
case "enclosure":
mp3 = xmlPullParser.getAttributeValue(null, "url");
// Log.d("Add", slika);
break;

case "description":
opis = res;
break;
}


if (naslov != null && opis != null && mp3 != null) {
if(itemObj) {
// Log.d("Add", naslov + opis);
// Dodamo oddajo samo v primeru da so vse ustrezne znacke pridobljene
item = new DataRSSmp3(naslov, mp3, opis);
}

naslov = null;
mp3 = null;
opis = null;

itemObj = false;
}
}

return item;
} finally {
inputStream.close();
}
}

}
29 changes: 29 additions & 0 deletions app/src/main/java/com/example/pp/podcastplayer/PodcastList.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
package com.example.pp.podcastplayer;

import android.os.Bundle;
import android.support.design.widget.FloatingActionButton;
import android.support.design.widget.Snackbar;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.Toolbar;
import android.view.View;

public class PodcastList extends AppCompatActivity {

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_podcast_list);
Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
setSupportActionBar(toolbar);

FloatingActionButton fab = (FloatingActionButton) findViewById(R.id.fab);
fab.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
Snackbar.make(view, "Replace with your own action", Snackbar.LENGTH_LONG)
.setAction("Action", null).show();
}
});
}

}
26 changes: 26 additions & 0 deletions app/src/main/res/layout/activity_podcast_list.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<?xml version="1.0" encoding="utf-8"?>
<android.support.design.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="com.example.pp.podcastplayer.PodcastList">

<android.support.design.widget.AppBarLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:theme="@style/AppTheme.AppBarOverlay">

<android.support.v7.widget.Toolbar
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:background="?attr/colorPrimary"
app:popupTheme="@style/AppTheme.PopupOverlay" />

</android.support.design.widget.AppBarLayout>

<include layout="@layout/content_podcast_list" />


</android.support.design.widget.CoordinatorLayout>
11 changes: 11 additions & 0 deletions app/src/main/res/layout/content_podcast_list.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_behavior="@string/appbar_scrolling_view_behavior"
tools:context="com.example.pp.podcastplayer.PodcastList"
tools:showIn="@layout/activity_podcast_list">

</android.support.constraint.ConstraintLayout>
1 change: 1 addition & 0 deletions app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,5 @@
<string name="action_settings">Settings</string>
<string name="action_add">Add podcast</string>
<string name="title_activity_download">DownloadActivity</string>
<string name="title_activity_podcast_list">PodcastList</string>
</resources>

0 comments on commit 5210ca2

Please sign in to comment.