I reproduce sound in listeview . I have a custom adapter , but it always fails the line where I put the int with the resources of the mp3 ! ono sure I'm perdnto something but do not know what ! advice on how to solve? thank you
git init .
git checkout -b my_branch (where my_branch is a new branch name you made up)
git remote add origin <url of your remote repository>
git fetch
git reset abc123
git commit -am "Here are my changes"
git checkout master (or whatever branch you were on before you deleted .git)
git merge my_branch
string
public class Adapter_animal extends ArrayAdapter<String> {
private final Activity context;
private final String[] animal;
private final int[] animal_id;
private MediaPlayer mp;
public Adapter_animal(Activity context, int mylist, String[] animal, int[] animal_id) {
super(context, R.layout.mylist, animal);
// TODO Auto-generated constructor stub
this.context=context;
this.animal = animal;
this.animal_id = animal_id;
}
public View getView(final int position,View view,ViewGroup parent) {
LayoutInflater inflater=context.getLayoutInflater();
View rowView=inflater.inflate(R.layout.mylist, null,true);
TextView txtTitle = (TextView) rowView.findViewById(R.id.titolo);
txtTitle.setText(animal[position]);
FloatingActionButton btn = (FloatingActionButton) rowView.findViewById(R.id.f1_btn);
btn.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
stopPlaying();
mp = MediaPlayer.create(Adapter_animal.this, animal_id); //error in this line "cannot resolve method
mp.start();
}
});
return rowView;
};
private void stopPlaying() {
if (mp != null) {
mp.stop();
mp.release();
mp = null;
}
}
答案 0 :(得分:0)
You're passing an array to a method that expects a single resource id...
import os import shutil import fnmatch import stat import itertools def copyToDir(src, dst, updateonly=True, symlinks=True, ignore=None, forceupdate=None, dryrun=False): def copySymLink(srclink, destlink): if os.path.lexists(destlink): os.remove(destlink) os.symlink(os.readlink(srclink), destlink) try: st = os.lstat(srclink) mode = stat.S_IMODE(st.st_mode) os.lchmod(destlink, mode) except OSError: pass # lchmod not available fc = [] if not os.path.exists(dst) and not dryrun: os.makedirs(dst) shutil.copystat(src, dst) if ignore is not None: ignorepatterns = [os.path.join(src, *x.split('/')) for x in ignore] else: ignorepatterns = [] if forceupdate is not None: forceupdatepatterns = [os.path.join(src, *x.split('/')) for x in forceupdate] else: forceupdatepatterns = [] srclen = len(src) for root, dirs, files in os.walk(src): fullsrcfiles = [os.path.join(root, x) for x in files] t = root[srclen+1:] dstroot = os.path.join(dst, t) fulldstfiles = [os.path.join(dstroot, x) for x in files] excludefiles = list(itertools.chain.from_iterable([fnmatch.filter(fullsrcfiles, pattern) for pattern in ignorepatterns])) forceupdatefiles = list(itertools.chain.from_iterable([fnmatch.filter(fullsrcfiles, pattern) for pattern in forceupdatepatterns])) for directory in dirs: fullsrcdir = os.path.join(src, directory) fulldstdir = os.path.join(dstroot, directory) if os.path.islink(fullsrcdir): if symlinks and dryrun is False: copySymLink(fullsrcdir, fulldstdir) else: if not os.path.exists(directory) and dryrun is False: os.makedirs(os.path.join(dst, dir)) shutil.copystat(src, dst) for s,d in zip(fullsrcfiles, fulldstfiles): if s not in excludefiles: if updateonly: go = False if os.path.isfile(d): srcdate = os.stat(s).st_mtime dstdate = os.stat(d).st_mtime if srcdate > dstdate: go = True else: go = True if s in forceupdatefiles: go = True if go is True: fc.append(d) if not dryrun: if os.path.islink(s) and symlinks is True: copySymLink(s, d) else: shutil.copy2(s, d) else: fc.append(d) if not dryrun: if os.path.islink(s) and symlinks is True: copySymLink(s, d) else: shutil.copy2(s, d) return fc
Convenience method to create a
public static MediaPlayer create (Context context, int resid)
for a given resource id. On success,MediaPlayer
will already have been called and must not be called again.When done with the
prepare()
, you should callMediaPlayer
, to free the resources. If not released, too manyrelease()
instances will result in an exception.Note that since
MediaPlayer
is called automatically in this method, you cannot change the audio stream type (seeprepare()
), audio session ID (seesetAudioStreamType(int)
) or audio attributes (seesetAudioSessionId(int)
of the newsetAudioAttributes(AudioAttributes)
.Parameters
MediaPlayer
- thecontext
to use
Context
- the raw resource id (resid
) for the resource to use as the datasourceReturns
R.raw.<something>
- aMediaPlayer
object, or null if creation failed