小编Spl*_*usa的帖子

更改按钮文本和操作 - android开发

我无法弄清楚如何更改按钮的文本和操作.我想要做的是有一个文本"play"的按钮,当点击它时,它将播放一首歌并将文本更改为"暂停".然后当你再次点击它时,它会暂停歌曲并将文字改为"播放".

我知道如何使用媒体播放器(编码),只是不知道如何编码按钮:

到目前为止我有:

final Button testButton = (Button) findViewById(R.id.button1);
testButton.setText("Play");
testButton.setOnClickListener( new View.OnClickListener() {

@Override
public void onClick (View v) {
mPlayer.start();
testButton.setText("Pause");
Run Code Online (Sandbox Code Playgroud)

android text button

18
推荐指数
1
解决办法
6万
查看次数

媒体播放器流网址,然后播放下一个网址

我目前有一个播放mp3文件的媒体播放器.当该文件完成后,代码是什么,以便它转到下一个url/mp3?

还有,是否有代码获取文件的名称并显示它?我该怎么做呢?

谢谢

编辑

看下面的代码:

package com.example.m3uplayer;

import android.app.Activity;
import android.media.AudioManager;
import android.media.MediaPlayer;
import android.net.Uri;
import android.os.Bundle;
import android.media.MediaPlayer.OnCompletionListener;

public class m3uPlayer extends Activity implements MediaPlayer.OnCompletionListener {
    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        //

        //http://dl.dropbox.com/u/24535120/AfroJack-UMF11-clip2.mp3

        //http://dl.dropbox.com/u/24535120/Avicii%20clip%201.mp3


        Uri myUri = Uri.parse("http://dl.dropbox.com/u/24535120/AfroJack-UMF11-clip2.mp3");

        MediaPlayer sdrPlayer = new MediaPlayer();

        try {
            sdrPlayer.setDataSource(this, myUri);//"http://mp1.somafm.com:8032");
            sdrPlayer.setAudioStreamType(AudioManager.STREAM_MUSIC);
            sdrPlayer.prepare(); //don't use prepareAsync for mp3 playback
        } catch (IOException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        } …
Run Code Online (Sandbox Code Playgroud)

audio streaming filenames android media-player

5
推荐指数
1
解决办法
1万
查看次数

进度条,而媒体播放器正在准备

我正在试图找出如何在我的媒体播放器准备流媒体文件时有一个"正在加载.请等待......"的进度条.现在发生的是它在准备好歌曲后显示.我怎样才能解决这个问题?

        mediaPlayerLoadingBar =ProgressDialog.show(PlaylistActivity.this, "", "Loading. Please wait...", true);         
                    /*dubstep stream*/
                    try {
                        dubstepMediaPlayer.setDataSource(dubstepPlaylistString[0]);
                        dubstepMediaPlayer.setAudioStreamType(AudioManager.STREAM_MUSIC);
                        dubstepMediaPlayer.prepare();

                    } catch (IllegalArgumentException e) {
                        // TODO Auto-generated catch block
                        e.printStackTrace();
                    } catch (SecurityException e) {
                        // TODO Auto-generated catch block
                        e.printStackTrace();
                    } catch (IllegalStateException e) {
                        // TODO Auto-generated catch block
                        e.printStackTrace();
                    } catch (IOException e) {
                        // TODO Auto-generated catch block
                        e.printStackTrace();
                    }


                    dubstepMediaPlayer.start();
                    if(dubstepMediaPlayer.isPlaying()){
                        mediaPlayerLoadingBar.dismiss();
                    }`
Run Code Online (Sandbox Code Playgroud)

编辑:这是我现在的代码:

`switch(pSelection){案例1:

                    new AsyncTask<Void, Void, Void>(){

                    @Override
                    protected void onPreExecute(){
                        mediaPlayerLoadingBar =ProgressDialog.show(PlaylistActivity.this, "", "Loading. Please wait...", …
Run Code Online (Sandbox Code Playgroud)

android stream media-player progress-bar

5
推荐指数
2
解决办法
9625
查看次数

Android-下载文件+状态栏通知放慢手机速度

我目前有一个asynctask从服务器下载mp3.当用户开始下载时,会创建状态栏通知.这将实时显示下载进度.我唯一担心的是手机放慢了几乎.有没有办法延迟显示的进度或使我的代码更快的方法?谢谢.

代码如下:

public class DownloadFile extends AsyncTask<String, String, String> {
    CharSequence contentText;
    Context context;
    CharSequence contentTitle;
    PendingIntent contentIntent;
    int HELLO_ID = 1;
    long time;
    int icon;
    CharSequence tickerText;
    File file;

    public void downloadNotification() {
        String ns = Context.NOTIFICATION_SERVICE;
        notificationManager = (NotificationManager) getSystemService(ns);

        icon = R.drawable.sdricontest;
        //the text that appears first on the status bar
        tickerText = "Downloading...";
        time = System.currentTimeMillis();

        notification = new Notification(icon, tickerText, time);

        context = getApplicationContext();
        //the bold font
        contentTitle = "Your download is in …
Run Code Online (Sandbox Code Playgroud)

notifications android download slowdown android-asynctask

5
推荐指数
2
解决办法
1万
查看次数

Android - 点击按钮,将项目添加到自定义列表视图

我目前有一个自定义列表视图,其中列表中的每个项目包含两行文本.我想要做的是每次用户点击按钮时,它会在列表中创建一个新项目,其中包含用户输入的文本.虽然我知道如何获取文本,但我无法在列表视图中添加新项目,因为我根本不知道从哪里开始.

这是我的代码:

public class MainFeedActivity extends ListActivity implements OnClickListener {
    View sendButton;
    EditText postTextField;
    TextView currentTimeTextView, mainPostTextView;
    ListView feedListView;
    String[] test;
    ArrayList<HashMap<String, String>> list;

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main_feed);

        //create button and implement on click listener
        sendButton = this.findViewById(R.id.sendPostButton);
        sendButton.setOnClickListener(this);

        list = new ArrayList<HashMap<String, String>>();

        //create the adapter for the list view
        SimpleAdapter adapter = new SimpleAdapter(
            this,
            list,
            R.layout.post_layout,
            new String[]{"time", "post"},
            new int[]{R.id.postTimeTextView, R.id.postTextView});
        //fill the list view with something - TEST
        fillData();
        //set list …
Run Code Online (Sandbox Code Playgroud)

android listview buttonclick

4
推荐指数
1
解决办法
5969
查看次数

Android webview底部带有admob广告

我整天都在沉溺于此,并且无法弄明白.我有一个webview,并希望在底部有一个admob广告.我的xml应该是什么样的?我应该在xml中配置admob还是使用代码?谢谢

xml android webview admob android-layout

3
推荐指数
2
解决办法
4517
查看次数

Android-从字符串中删除URL百分比符号

我有一个如下所示的网址:

自由女神%21%20英尺%20Whiskey%20Pete%20-%20Thunderfist%20%28Original%20Mix%29.mp3

我试图从中提取出来的话.现在,我正在使用string.replace("%21", "!")每个%20,%29等,因为每个段代表不同的字符或空格.有没有办法将这些符号和数字转换为它们实际意味着什么?

谢谢.

java string url android symbols

3
推荐指数
2
解决办法
4304
查看次数

活动已经泄露窗口

在我的启动画面中,我做了它,以便检测是否启用了wifi或3g.如果不是,则会出现一个对话框,提示用户退出并打开其中一个.如果它打开,则代码将继续.我的logcat中一直有一个关于我的活动有一个泄漏窗口的错误.我不知道如何解决这个问题.代码和logcat如下.有任何想法吗?

这是我的代码:

//create alert dialog for wifi and 3g
connectionDialog = new AlertDialog.Builder(SplashMain.this).create();
Log.d(TAG, "dialog created");
connectionDialog.setTitle("Wifi or 3G not detected. Please enable either Wifi or 3G");
connectionDialog.setButton("Exit", new DialogInterface.OnClickListener() {
    @Override
    public void onClick(DialogInterface dialog, int which) {
            finish();
    }
});

wifiHandler = new Handler();
setContentView(R.layout.splashscreen);  //Make the splash screen load first
Thread splashScreenTimer = new Thread(){ //create a timer for the splash screen
    public void run(){      //create a run class
        Looper.prepare();   //prepare looper
        try{            //methods within the run …
Run Code Online (Sandbox Code Playgroud)

android window android-activity

3
推荐指数
1
解决办法
2万
查看次数

Android - 在AsyncTask中执行后执行

我目前有一个asyncTask在preexecute开始加载栏,在后台发送一些东西到服务器,并在后执行解除对话框并启用一个按钮.但是,由于doInBackground返回null,我的post执行没有执行.我想弄明白我能做什么让postExecute运行.有任何想法吗?谢谢

码:

class DatabaseAsync extends AsyncTask<Void,Void,Void>{
        @Override
        protected void onPreExecute(){
            dialog = ProgressDialog.show(MainFeedActivity.this, null, "Posting...");
        }

        @Override
        protected Void doInBackground(Void... arg0) {
            Log.d(TAG, "send to databse");
            SendToDatabase();
            Log.d(TAG, "sent to database - DONE");

            //dialog.dismiss();

            //sendButton.setEnabled(true);

            return null;
        }

        protected void onPostExecute(){
            Log.d(TAG, "p execute");
            dialog.dismiss();
            sendButton.setEnabled(true);
            Log.d(TAG, "done executing");
        }

    }
Run Code Online (Sandbox Code Playgroud)

database android dialog button android-asynctask

3
推荐指数
1
解决办法
1万
查看次数

Android - 压缩位图,然后将其保存到SDCARD的活动结果中

我一直在讨论这个问题,并不确定该怎么做.我要做的是:拍照,压缩到png(保持原始尺寸),然后将其保存到sdCard.我需要这样做的原因是因为我必须再次重新压缩它,然后Base64编码它,以便我可以将它发送到服务器.问题是1.文件太大2.我的内存不足3.不确定我是否正确执行此操作.

谢谢你的帮助

这是我的代码:

@Override
public void onClick(View button) {
    switch (button.getId()) {
        case R.id.cameraButton:
            Intent cameraIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
            cameraIntent.putExtra(android.provider.MediaStore.EXTRA_OUTPUT,
                Uri.fromFile(new File("/sdcard/test.png")));
            startActivityForResult(cameraIntent, CAMERA_PIC_REQUEST);
            break;
        case R.id.galleryButton:
            sendToDatabase();
            break;
    }
}

// Camera on activity for result - save it as a bmp and place in imageview
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
    if (requestCode == CAMERA_PIC_REQUEST) {
        // do something
    }

    if (resultCode == Activity.RESULT_OK) {
        Log.d(TAG, "result ok");

        picture = BitmapFactory.decodeFile("/sdcard/test.png");

        // Create string to …
Run Code Online (Sandbox Code Playgroud)

memory compression android bitmap android-camera

3
推荐指数
1
解决办法
1万
查看次数

for循环使用原始音乐阵列android

我目前正在尝试创建一个for循环,它将播放一个原始文件,当它完成后,它将继续到数组中的下一个声音文件.它目前正在播放所有文件.关于我如何解决这个问题的任何建议?我认为on on completion listener可能存在问题,但不确定.谢谢.

我的代码:

package com.example.mediatest;



    int[] myMusic = {R.raw.caralarm, R.raw.phonebusysignal, R.raw.phoneoffhook};



    MediaPlayer mp = new MediaPlayer();



   for (int y =0; y<3; y++){
       mp = MediaPlayer.create(this, myMusic[y]);
       mp.start();
       mp.setOnCompletionListener(new OnCompletionListener(){

        @Override
        public void onCompletion(MediaPlayer mp) {
            // TODO Auto-generated method stub

        }

       });
   }
Run Code Online (Sandbox Code Playgroud)

arrays android for-loop media-player

1
推荐指数
1
解决办法
4851
查看次数

用随机数android/java填充数组

我在执行以下操作时遇到了麻烦,并且不知道该怎么做:我想填充一个用随机数字(1-40)生成的数组,并且还要使它不会重复.另外,有没有办法让数组使用自己的下一个值.所以我要说测试[1] ="3",然后测试[2] ="6".反正有没有让它转到下一个值而不是调用test [2]?

非常感谢

java arrays random int android

1
推荐指数
1
解决办法
5027
查看次数

媒体播放器流式传输,退出应用音乐应该停止

我目前有一个媒体播放器流式传输一些mp3文件.我想要做的是如果用户按下主页按钮退出应用程序,音乐将停止播放.我该怎么做呢?

audio android exit media-player

0
推荐指数
1
解决办法
4887
查看次数