Rotation tag mp4parser android - android

I'm trying to get the rotation information in the MP4 video, I'm trying to use mp4parser for this but I'm not sure how can I get it, I'm doing this,
IsoFile isoFile = null;
try {
isoFile = new IsoFile(filePath);
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
List<Box> boxes = isoFile.getBoxes();
for (Box box : boxes) {
System.out.println(box);
}
and the output is this
I/System.out(23548): FileTypeBox[majorBrand=isom;minorVersion=0;compatibleBrand=isom;compatibleBrand=3gp4]
I/System.out(23548): MovieBox[]
I/System.out(23548): com.coremedia.iso.boxes.FreeBox#0
I/System.out(23548): MediaDataBox{size=7913167}
Any idea how can I get the rotation tag value?
Update 1 The working code
import java.io.File;
import java.io.FileInputStream;
import android.app.Activity;
import android.os.Bundle;
import com.coremedia.iso.IsoFile;
import com.coremedia.iso.IsoTypeReader;
import com.coremedia.iso.boxes.Box;
import com.coremedia.iso.boxes.MovieBox;
import com.coremedia.iso.boxes.UserDataBox;
import com.googlecode.mp4parser.authoring.Movie;
import com.googlecode.mp4parser.authoring.container.mp4.MovieCreator;
import com.googlecode.mp4parser.util.Matrix;
public class MainActivity extends Activity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
String filePath = "/storage/emulated/0/test/test.mp4";
Activity activity = (Activity) MainActivity.this;
movie = MovieCreator.build(filePath);
Matrix matrix = movie.getMatrix();
}
}

You need to get Movie object from the IsoFile or read it with MovieCreator.build(), then with movie.getMatrix() obtain what is the type of matrix: Matrix.ROTATE_O, Matrix.ROTATE_90, Matrix.ROTATE_180, Matrix.ROTATE_270
String filePath = "/path/to/movie/file.mp4"
Movie movie = MovieCreator.build(new FileInputStream(new File(filePath)).getChannel());
Matrix matrix = movie.getMatrix();

Related

Bluemix: How to insert JSON in Cloudant in Android with Replicator?

I am finding it difficult to make this simple upload. I've used all encontrandos tutorials on the internet such as Bluelist and android-sync. I already have a database created within the service. My code is as follows:
MainActivity.java
package com.example.engenharia.replicator;
import android.content.Context;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.widget.Toast;
import com.cloudant.sync.datastore.BasicDocumentRevision;
import com.cloudant.sync.datastore.Datastore;
import com.cloudant.sync.datastore.DatastoreException;
import com.cloudant.sync.datastore.DatastoreManager;
import com.cloudant.sync.datastore.DocumentBodyFactory;
import com.cloudant.sync.datastore.DocumentException;
import com.cloudant.sync.datastore.DocumentRevision;
import com.cloudant.sync.datastore.MutableDocumentRevision;
import com.cloudant.sync.query.IndexManager;
import com.cloudant.sync.replication.ReplicatorBuilder;
import com.cloudant.sync.replication.Replicator;
import java.io.File;
import java.net.URI;
import java.util.HashMap;
import java.util.Map;
import java.util.concurrent.CountDownLatch;
public class MainActivity extends AppCompatActivity {
private static final String DATASTORE_MANGER_DIR = "data";
private Datastore DataStore;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
try {
URI uri = new URI(my_uri);
File path = getApplicationContext().getDir(DATASTORE_MANGER_DIR, Context.MODE_PRIVATE);
DatastoreManager manager = new DatastoreManager(path.getAbsolutePath());
DataStore = manager.openDatastore("banco0"); //banco0 is the DB created in Cloudant NoSQL service.
// Create a replicator that replicates changes from the local
// datastore to the remote database.
Replicator replicator = ReplicatorBuilder.push().to(uri).from(DataStore).build();
// Use a CountDownLatch to provide a lightweight way to wait for completion
CountDownLatch latch = new CountDownLatch(1);
Listener listener = new Listener(latch);
replicator.getEventBus().register(listener);
replicator.start();
latch.await();
replicator.getEventBus().unregister(listener);
if(replicator.getState() != Replicator.State.COMPLETE){
System.out.println("Error replicating TO remote");
System.out.println(listener.error);
} else {
System.out.println(String.format("Replicated %d documents in %d batches",
listener.documentsReplicated, listener.batchesReplicated));
}
}catch (Exception e){
e.printStackTrace();
}
}
public DocumentRevision createDocument() {
MutableDocumentRevision rev = new MutableDocumentRevision();
rev.body = DocumentBodyFactory.create(HashMap());
try {
return DataStore.createDocumentFromRevision(rev);
} catch (DocumentException e) {
//throw new RuntimeException(e);
e.printStackTrace();
return null;
}
}
public Map<String, Object> HashMap() {
HashMap<String, Object> map = new HashMap<String, Object>();
HashMap<String, String> map1 = new HashMap<String, String>();
map1.put("Street", "121");
map1.put("Street1", "12112");
map1.put("Street123", "1211111");
String[] array1 = new String[]{"Cloudant", "NoSQL", "JSON"};
map.put("address", map1);
map.put("description", "This is sample description");
map.put("skills", array1);
return map;
}
}
listener.java
package com.example.engenharia.replicator;
import com.cloudant.sync.notifications.ReplicationCompleted;
import com.cloudant.sync.notifications.ReplicationErrored;
import com.cloudant.sync.replication.ErrorInfo;
import com.google.common.eventbus.Subscribe;
import com.cloudant.sync.replication.ReplicatorBuilder;
import com.cloudant.sync.replication.Replicator;
import java.util.concurrent.CountDownLatch;
/**
* Created by engenharia on 19/08/16.
*/
public class Listener {
private final CountDownLatch latch;
public ErrorInfo error = null;
public int documentsReplicated;
public int batchesReplicated;
Listener(CountDownLatch latch) {
this.latch = latch;
}
#Subscribe
public void complete(ReplicationCompleted event) {
this.documentsReplicated = event.documentsReplicated;
this.batchesReplicated = event.batchesReplicated;
latch.countDown();
}
#Subscribe
public void error(ReplicationErrored event) {
this.error = event.errorInfo;
latch.countDown();
}
}
Executing this code I have the follow error:
CouchException: error: forbidden, reason: server_admin access is
required for this request, statusCode: 403, msg: null, cause: null
But I am the admin!
How do I fix the problem or what is the solution?

I need to get metadata of music albums from sdcard in a listview

import android.app.Activity;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.Color;
import android.media.MediaMetadataRetriever;
import android.os.Bundle;
import android.widget.ImageView;
import android.widget.TextView;
public class MetaExtractActivity extends Activity { ImageView album_art;
TextView album, artist, genre; MediaMetadataRetriever metaRetriever;
byte[] art;
#Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState);
setContentView(R.layout.main);
getInit();
// Ablum_art retrieval code
// metaRetriever = new MediaMetadataRetriever();
metaRetriever.setDataSource("/sdcard/audio.mp3");
try
{
art = metaRetriever.getEmbeddedPicture();
Bitmap songImage = BitmapFactory .decodeByteArray(art, 0, art.length); album_art.setImageBitmap(songImage);
album.setText(metaRetriever .extractMetadata(MediaMetadataRetriever.METADATA_KEY_ALBUM)); artist.setText(metaRetriever .extractMetadata(MediaMetadataRetriever.METADATA_KEY_ARTIST)); genre.setText(metaRetriever .extractMetadata(MediaMetadataRetriever.METADATA_KEY_GENRE));
}
catch (Exception e) { album_art.setBackgroundColor(Color.GRAY);
album.setText("Unknown Album");
artist.setText("Unknown Artist");
genre.setText("Unknown Genre");
} }
// Fetch Id's form xml public void getInit() { album_art = (ImageView)findViewById(R.id.album_art);
album = (TextView) findViewById(R.id.Album);
artist = (TextView) findViewById(R.id.artist_name);
genre = (TextView) findViewById(R.id.genre);
} }
You can use the Library Apache Tika , this will help you get the available information of the file as long as it is available.
Note : There is no guarantee that your file contains the meta-data you need.
Relevant Snippet using Java:
public static void main(String[] args) {
String fileLocation = "C:/desktopname/songs/song.mp3";
try {
InputStream input = new FileInputStream(new File(fileLocation));
ContentHandler handler = new DefaultHandler();
Metadata metadata = new Metadata();
Parser parser = new Mp3Parser();
ParseContext parseCtx = new ParseContext();
parser.parse(input, handler, metadata, parseCtx);
input.close();
// List all metadata
String[] metadataNames = metadata.names();
for(String name : metadataNames){
System.out.println(name + ": " + metadata.get(name));
}
// Retrieve the necessary info from metadata
// Names - title, xmpDM:artist etc. - mentioned below may differ based
System.out.println("----------------------------------------------");
System.out.println("Title: " + metadata.get("title"));
System.out.println("Artists: " + metadata.get("xmpDM:artist"));
System.out.println("Composer : "+metadata.get("xmpDM:composer"));
System.out.println("Genre : "+metadata.get("xmpDM:genre"));
System.out.println("Album : "+metadata.get("xmpDM:album"));
} catch (Exception e) { }
}
To use this in Android , you just need to acquire the right URI of the file then use the code above.

Working with Android and Jsoup parsing a table to a certain element

The problem I am having is that I am trying to parse this website but I am getting thiserror . I am new to Jsoup and not quite sure whats making the error. Is there a way to stop parsing on certain element like if i want it to stop on first instance of Bobby? (row : Cindy : Mike : Bobby). Thanks in advance!
import android.app.Activity;
import android.os.Bundle;
import android.os.StrictMode;
import android.os.StrictMode.ThreadPolicy;
import org.jsoup.Jsoup;
import java.io.IOException;
import org.jsoup.nodes.Document;
import org.jsoup.nodes.Element;
import org.jsoup.select.Elements;
public class tableScreen extends Activity {
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.table);
takeTable();
}
public static int SDK_INT = android.os.Build.VERSION.SDK_INT;
public void takeTable()
{
Document doc = null;
if (SDK_INT >= 10)
{
ThreadPolicy tp = ThreadPolicy.LAX;
StrictMode.setThreadPolicy(tp);
}
try{
doc = Jsoup.connect("http://www.htmlgoodies.com/tutorials/tables/article.php/3479851").get();
System.out.println("1");
Element containingDiv = doc.select(".body").first();
System.out.println("2");
Elements table = containingDiv.select("table");
System.out.println("3");
Elements rows = table.select("tr");
System.out.println("4");
for (Element row : rows)
{
System.out.println("row: "+row.child(0).text()+" : "+row.child(1).text()+" : "+ row.child(2).text());
}
}
catch (IOException e)
{
e.printStackTrace();
}
}
}
OK guys I manage to fix it ,
doc = Jsoup.connect("http://www.htmlgoodies.com/tutorials/tables/article.php/3479851").get();
Element containingDiv = doc.select("table").first();
Elements table = containingDiv.select("tbody");
Elements rows = table.select("tr");

no communication between pub/sub code in android using zeromq

I tried to implement a simple publisher and subscriber in android using zeromq. When i try to debug it loops in subscriber recv. I dont know where i am going wrong. I think it is not able to get any data from the publisher.
Below is the code :subscriber
package com.example.jeromqps;
import java.util.*;
import org.jeromq.ZMQ;
import android.os.AsyncTask;
import android.os.Message;
import android.os.Messenger;
import android.os.RemoteException;
public class client implements Runnable {
Messenger messenger;
public client()
{
System.out.println("client started");
}
#Override
public void run()
{
ZMQ.Context context=ZMQ.context(1);
System.out.println("collecting data from server");
ZMQ.Socket subscriber=context.socket(ZMQ.SUB);
subscriber.connect("tcp://localhost:4444");
String code="10001";
subscriber.subscribe(code.getBytes());
int totalvalue=0;
//store the data in a data structure
for(int i=0;i<10;i++)
{
byte[] msg = subscriber.recv(0);
String string=new String(subscriber.recv(0));
StringTokenizer sscanf=new StringTokenizer(string," ");
int value=Integer.valueOf(sscanf.nextToken());
String string= new String(msg);
System.out.println();
totalvalue+=value;
}
int avg=totalvalue;
Message msg1=Message.obtain();
msg1.obj=string;
try {
messenger.send(msg1);
System.out.println("sent to main");
} catch (RemoteException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
subscriber.close();
context.term();
}
}
The publisher code is below
package com.example.jeromqps;
import java.util.*;
import org.jeromq.*;
public class server implements Runnable{
public server()
{
System.out.println("server started");
}
#Override
public void run()
{
ZMQ.Context context=ZMQ.context(1);
ZMQ.Socket publisher=context.socket(ZMQ.PUB);
publisher.bind("tcp://*:4444");
Random srandom=new Random(System.currentTimeMillis());
System.out.println("in server");
while(!Thread.currentThread().isInterrupted())
{ //System.out.println("in while")
int zipcode =1000 +srandom.nextInt(10000);
int temperature = srandom.nextInt(215) - 80 + 1;
String update = String.format("%05d %d", zipcode, temperature);
String update="publisher";
publisher.send(update.getBytes(),0);
}
publisher.close();
context.term();
}
}
Main is below:
package com.example.jeromqps;
import android.os.Bundle;
import android.app.Activity;
import android.view.Menu;
import android.app.Activity;
import android.app.AlertDialog;
import android.os.Bundle;
import android.os.Message;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;
import android.os.Handler;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Date;
public class MainActivity extends Activity implements Handler.Callback {
private TextView textView;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
new Thread(new server()).start();
new Thread(new client()).start();
}
#Override
public boolean handleMessage(Message arg0)
{
String str = new String((byte[]) arg0.obj);
System.out.println("****");
System.out.println(str);
//new AlertDialog.Builder(this).setMessage(str).show();
System.out.println("****");
textView.append(str+ "\n");
return false;
}
}
In program loops at byte[] msg = subscriber.recv(0); in the subscribers class. Where am i going wrong?Am i missing something?
First of all, you've got some errors in the code:
In the publisher, update is defined twice
String update = String.format("%05d %d", zipcode, temperature);
String update= "publisher";
You have a similar problem in the subscriber code, string is defined twice...
String string = new String(subscriber.recv(0));
String string = new String(msg);
In the subscriber, you're receiving messages twice in the same iteration..
byte[] msg = subscriber.recv(0);
String string = new String(subscriber.recv(0));
...you only need this in the loop to receive...
String string = new String(subscriber.recv(0));
Try fixing those problems and see how far you get...
This isn't a solution to the question posted here, but reading this question I noticed that 0 was specified as the second parameter in the send(...) method, which subsequently matches the parameter set in the recv(...) method.
I have a simple pub/sub system set up and couldn't figure out why messages weren't being sent. I was using recv(0) but was specifying some random flag in the send(...) method. Changing the value to 0 fixed my issues.
Figured I'd post this here as it was from reading through the code in the question that I happened to have that thought. So maybe this will help someone else in the future.

Minitemplator on android, how to access to template file in asset directory?

I am trying to integrate Minitemplator (http://www.source-code.biz/MiniTemplator/) to an application of android but i am little lost.
I can access to the template file, the template file is in asset directory and i try to get the file at this way:
Uri path = Uri.parse("file:///android_asset/index.html");
and instantiate the object at this way:
MiniTemplator t = new MiniTemplator(path.getPath());
but it send me an io exception that file or folder doesn't exists.
how is the correct way to send the file to instantiate my minitemplator object?
This is the complete code:
package com.kentverger.minitemplator;
import java.io.File;
import java.io.IOException;
import biz.source_code.miniTemplator.MiniTemplator;
import biz.source_code.miniTemplator.MiniTemplator.TemplateSyntaxException;
import android.net.Uri;
import android.os.Bundle;
import android.app.Activity;
import android.util.Log;
import android.view.Menu;
import android.webkit.WebView;
public class Template extends Activity {
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_template);
WebView index = (WebView) findViewById(R.id.indexWebView);
Uri path = Uri.parse("file:///android_asset/index.html");
try {
MiniTemplator t = new MiniTemplator(path.getPath());
t.setVariable("titulo", "Hola mundo generado desde java");
String html_code = t.generateOutput();
index.loadData(html_code, "text/html", null);
} catch (TemplateSyntaxException e) {
Log.d("ERROR 1", e.getMessage());
} catch (IOException e) {
Log.d("ERROR 2", e.getMessage());
}
}
#Override
public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.activity_template, menu);
return true;
}
}
I solve my problem loading the template from a string instead a html file.
First I have to create a specification object that will content the template String
MiniTemplator.TemplateSpecification templateSpec = new MiniTemplator.TemplateSpecification();
Then add the template String to templateString property
templateSpec.templateText = "<html><body><h1>${hello}</h1></body></html>";
Next we have to instantiate the Minitemplator object with the speciciations object
t = new MiniTemplator(templateSpec);
And we already to change the values of the variables in the template like this:
t.setVariable("hello", "Hola Mundo!");
Thanks a lot :)
MiniTemplator miniTemplator = openHtmlFileFromAssert(activity, "test.html");
Try this method is working and is help to read html file from assert folder
public MiniTemplator openHtmlFileFromAssert(Activity activity, String fileName) {
try {
AssetManager assetManager = activity.getAssets();
InputStream inputStream = assetManager.open(fileName);
MiniTemplator.Builder templateBuilder = new MiniTemplator.Builder();
return templateBuilder.build(inputStream, Charset.defaultCharset());
} catch (IOException e) {
e.printStackTrace();
return null;
}
}

Categories

Resources