Android Mediaplayer Won't Stop
I have the following code to play an mp3 file from the web and this is
working but when I use the stop functionality the audio does not stop. Can
anyone point me towards a resource to find out more about this or tell me
where I am going wrong? Thanks.
showAudio.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
MediaPlayer mediaPlayer = new MediaPlayer();
mediaPlayer.setAudioStreamType(AudioManager.STREAM_MUSIC);
if (!showAudio.getText().equals("Stop")) {
try {
String url = lblAudio.getText().toString();
if (url.length() > 2) {
mediaPlayer.setDataSource(url);
mediaPlayer.prepare();
mediaPlayer.start();
showAudio.setText("Stop");
}
} catch (Exception e) {
Toast.makeText(getBaseContext(), "Sorry, there was a
problem playing audio.", Toast.LENGTH_SHORT).show();
}
} else {
try {
mediaPlayer.stop();
mediaPlayer.release();
} catch (Exception ex) {
ex.printStackTrace();
}
showAudio.setText("Audio");
}
}
});
Boisse
Thursday, 3 October 2013
Wednesday, 2 October 2013
From Query resultset to a JOptionPaneDialog
From Query resultset to a JOptionPaneDialog
I have a sparql query which returns some results. I need to let the user
to choose which of these results he will use next. I have coded this with
scanner, but I want to convert it now to a joptionpanedialog so that it is
more user friendly. I assume it is achieved via
JOptionPane.showInputDialog. However I dont know how to "translate" the
resultset in the object list of the joptionpane in the right format, and
then extract the selected elements. Any ideas how could I achieve this?
Thanks in advance
Query query = QueryFactory.create(queryString);
QueryExecution qe=
QueryExecutionFactory.create(query, model);
ResultSet resultset = qe.execSelect();
ResultSet results =
ResultSetFactory.copyResults(resultset);
final ResultSet results2 =
ResultSetFactory.copyResults(results);
System.out.println( "== Available Options ==" );
ResultSetFormatter.out(System.out, results, query);
System.out.println( "== Select Option ==" );
System.out.println( "== Type 0,1,2,3.. to choose Option
==" );
Scanner input = new Scanner( System.in );
final String inputs ;
inputs = input.next();
final String[] indices = inputs.split("\\s*,\\s*");
final List<QuerySolution> selectedSolutions = new
ArrayList<QuerySolution>( indices.length ) {{
final List<QuerySolution> solutions =
ResultSetFormatter.toList( results2 );
for ( final String index : indices ) {
add( solutions.get( Integer.valueOf( index )));
}
}};
String s = selectedSolutions.toString();
Pattern p = Pattern.compile("#([^>]+)>");
Matcher m = p.matcher(s);
I have a sparql query which returns some results. I need to let the user
to choose which of these results he will use next. I have coded this with
scanner, but I want to convert it now to a joptionpanedialog so that it is
more user friendly. I assume it is achieved via
JOptionPane.showInputDialog. However I dont know how to "translate" the
resultset in the object list of the joptionpane in the right format, and
then extract the selected elements. Any ideas how could I achieve this?
Thanks in advance
Query query = QueryFactory.create(queryString);
QueryExecution qe=
QueryExecutionFactory.create(query, model);
ResultSet resultset = qe.execSelect();
ResultSet results =
ResultSetFactory.copyResults(resultset);
final ResultSet results2 =
ResultSetFactory.copyResults(results);
System.out.println( "== Available Options ==" );
ResultSetFormatter.out(System.out, results, query);
System.out.println( "== Select Option ==" );
System.out.println( "== Type 0,1,2,3.. to choose Option
==" );
Scanner input = new Scanner( System.in );
final String inputs ;
inputs = input.next();
final String[] indices = inputs.split("\\s*,\\s*");
final List<QuerySolution> selectedSolutions = new
ArrayList<QuerySolution>( indices.length ) {{
final List<QuerySolution> solutions =
ResultSetFormatter.toList( results2 );
for ( final String index : indices ) {
add( solutions.get( Integer.valueOf( index )));
}
}};
String s = selectedSolutions.toString();
Pattern p = Pattern.compile("#([^>]+)>");
Matcher m = p.matcher(s);
Query to multiple each row's cost times quantity and sum
Query to multiple each row's cost times quantity and sum
I'm having a difficult time getting this to work. I have a table that
looks like this:
quantity cost
-------- ----
5 150
2 100
and I'd like to select a single result which should be 950. When I use
group by the entire quantities gets multiplied times the entire cost
I'm having a difficult time getting this to work. I have a table that
looks like this:
quantity cost
-------- ----
5 150
2 100
and I'd like to select a single result which should be 950. When I use
group by the entire quantities gets multiplied times the entire cost
Android Viewpager in Fragment
Android Viewpager in Fragment
So I'm trying to make an Swipe Image slider in a fragment and this is what
I've Got The app crashes when I set the adapter , Not sure exactly where
the problem is.
It was working ok before I put the viewpager in a fragment
public class Slider extends Fragment {
private static final int NUM_PAGES = 5;
private TheAdapter adapter;
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
// TODO Auto-generated method stub
View view =inflater.inflate(R.layout.activity_reader, container, false);
ViewPager pager = (ViewPager) view.findViewById(R.id.pager);
adapter = new TheAdapter(getFragmentManager());
pager.setAdapter(adapter);
return view;
}
@Override
public void onViewCreated(View view, Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onViewCreated(view, savedInstanceState);
}
And this is the adapter class
public class TheAdapter extends FragmentStatePagerAdapter{
private static final int NUM_PAGES = 5;
LayoutInflater inflater;
public TheAdapter(android.support.v4.app.FragmentManager fm) {
super(fm);
// TODO Auto-generated constructor stub
}
@Override
public boolean isViewFromObject(View view, Object object) {
// TODO Auto-generated method stub
return view == ((ViewGroup) object);
}
@Override
public void destroyItem(ViewGroup container, int position, Object
object) {
// TODO Auto-generated method stub
((ViewPager) container).removeView((View)object);
}
public Fragment getItem(int arg0) {
// TODO Auto-generated method stub
return new Slider();
}
@Override
public void destroyItem(View container, int position, Object object) {
// TODO Auto-generated method stub
super.destroyItem(container, position, object);
}
@Override
public int getCount() {
// TODO Auto-generated method stub
return NUM_PAGES;
}}
}
So I'm trying to make an Swipe Image slider in a fragment and this is what
I've Got The app crashes when I set the adapter , Not sure exactly where
the problem is.
It was working ok before I put the viewpager in a fragment
public class Slider extends Fragment {
private static final int NUM_PAGES = 5;
private TheAdapter adapter;
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
// TODO Auto-generated method stub
View view =inflater.inflate(R.layout.activity_reader, container, false);
ViewPager pager = (ViewPager) view.findViewById(R.id.pager);
adapter = new TheAdapter(getFragmentManager());
pager.setAdapter(adapter);
return view;
}
@Override
public void onViewCreated(View view, Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onViewCreated(view, savedInstanceState);
}
And this is the adapter class
public class TheAdapter extends FragmentStatePagerAdapter{
private static final int NUM_PAGES = 5;
LayoutInflater inflater;
public TheAdapter(android.support.v4.app.FragmentManager fm) {
super(fm);
// TODO Auto-generated constructor stub
}
@Override
public boolean isViewFromObject(View view, Object object) {
// TODO Auto-generated method stub
return view == ((ViewGroup) object);
}
@Override
public void destroyItem(ViewGroup container, int position, Object
object) {
// TODO Auto-generated method stub
((ViewPager) container).removeView((View)object);
}
public Fragment getItem(int arg0) {
// TODO Auto-generated method stub
return new Slider();
}
@Override
public void destroyItem(View container, int position, Object object) {
// TODO Auto-generated method stub
super.destroyItem(container, position, object);
}
@Override
public int getCount() {
// TODO Auto-generated method stub
return NUM_PAGES;
}}
}
Tuesday, 1 October 2013
c++ operator overloading. Function to get private value from overload
c++ operator overloading. Function to get private value from overload
I have trouble getting the "print" function in this class to get the right
total
class PRN {
private:
typedef pair < string, int > P;
int sz, // map size – no of distinct words
cnt, // counter for printing
total; // no of words
public:
// constructor
PRN ( const int& s = 1, const int& c = 0, const int& t = 0 ){
cnt= c;
total = t;
sz = s;
}
void operator ( ) ( const P& p ){
total += p.second;
cout << total;
}// overloaded operator, where P is defined as
// typedef pair < string, int > P;
void print () const{
cout <<"no of words in output list : " << total << endl;
}
};
then in my main i call
PRN p (m.size());
for_each(m.begin(),m.end(),p);
p.print();
m is a map containing some values(string, int); The operator is adding
because im printing them and I can see they are getting added but when I
called p.print() it returns zero for the "total".
Any suggestions? Thanks
I have trouble getting the "print" function in this class to get the right
total
class PRN {
private:
typedef pair < string, int > P;
int sz, // map size – no of distinct words
cnt, // counter for printing
total; // no of words
public:
// constructor
PRN ( const int& s = 1, const int& c = 0, const int& t = 0 ){
cnt= c;
total = t;
sz = s;
}
void operator ( ) ( const P& p ){
total += p.second;
cout << total;
}// overloaded operator, where P is defined as
// typedef pair < string, int > P;
void print () const{
cout <<"no of words in output list : " << total << endl;
}
};
then in my main i call
PRN p (m.size());
for_each(m.begin(),m.end(),p);
p.print();
m is a map containing some values(string, int); The operator is adding
because im printing them and I can see they are getting added but when I
called p.print() it returns zero for the "total".
Any suggestions? Thanks
Nested loops for menus (basic c++)
Nested loops for menus (basic c++)
I'm running into errors where they say that a, q, h, etc aren't declared
variables, but I'm not sure how to fix this. Here is an example of my
code.
I'm also getting an error where it doesn't recognize userinp inside the
while loop, but I'm not sure how to transfer the variable storage from
outside the while loop to inside the while loop without declaring a global
variable, which I want to avoid.
Last question: I want to be able to have any key immediately return to the
main menu after each menu item, but I'm not sure what to use for that.
Any help is greatly appreciated!
//Runs a program with a menu that the user can navigate through different
options with via text input
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <ctype.h>
#include <string>
using namespace std;
int main()
{
int userinp;
cout<<"Here is the menu:" << endl;
cout<<"Help(H) addIntegers(A) subDoubles(D) Quit(Q)";
cin >> userinp;
userinp = tolower(userinp);
while userinp != q //loop while no q is input
{
if userinp == h
{
cout <<"This is the help menu. Upon returning to the main
menu, input A or a to add 2 intergers." << endl;
cout <<"Input D or d to subtract 2 doubles. Input Q or q to
quit.";
}
if userinp == a
{
int a, b, result;
cout <<"Enter two integers:";
cin << a << b;
result = a + b;
cout << "The sum of " << a << " + " << b << " = " << result;
}
}
}
I'm running into errors where they say that a, q, h, etc aren't declared
variables, but I'm not sure how to fix this. Here is an example of my
code.
I'm also getting an error where it doesn't recognize userinp inside the
while loop, but I'm not sure how to transfer the variable storage from
outside the while loop to inside the while loop without declaring a global
variable, which I want to avoid.
Last question: I want to be able to have any key immediately return to the
main menu after each menu item, but I'm not sure what to use for that.
Any help is greatly appreciated!
//Runs a program with a menu that the user can navigate through different
options with via text input
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <ctype.h>
#include <string>
using namespace std;
int main()
{
int userinp;
cout<<"Here is the menu:" << endl;
cout<<"Help(H) addIntegers(A) subDoubles(D) Quit(Q)";
cin >> userinp;
userinp = tolower(userinp);
while userinp != q //loop while no q is input
{
if userinp == h
{
cout <<"This is the help menu. Upon returning to the main
menu, input A or a to add 2 intergers." << endl;
cout <<"Input D or d to subtract 2 doubles. Input Q or q to
quit.";
}
if userinp == a
{
int a, b, result;
cout <<"Enter two integers:";
cin << a << b;
result = a + b;
cout << "The sum of " << a << " + " << b << " = " << result;
}
}
}
Does every linear group admit a subgroup of dimension 1=?iso-8859-1?Q?=3F_=96_mathoverflow.net?=
Does every linear group admit a subgroup of dimension 1? – mathoverflow.net
Suppose that $G$ is a linear group of positive dimension, defined over
some field $k$. Is that true, that $G$ admits a (closed) one-dimensional
subgroup? I'm pretty much sure this is true in ...
Suppose that $G$ is a linear group of positive dimension, defined over
some field $k$. Is that true, that $G$ admits a (closed) one-dimensional
subgroup? I'm pretty much sure this is true in ...
Subscribe to:
Comments (Atom)