<tfoot id='imQhf'></tfoot>

    1. <i id='imQhf'><tr id='imQhf'><dt id='imQhf'><q id='imQhf'><span id='imQhf'><b id='imQhf'><form id='imQhf'><ins id='imQhf'></ins><ul id='imQhf'></ul><sub id='imQhf'></sub></form><legend id='imQhf'></legend><bdo id='imQhf'><pre id='imQhf'><center id='imQhf'></center></pre></bdo></b><th id='imQhf'></th></span></q></dt></tr></i><div id='imQhf'><tfoot id='imQhf'></tfoot><dl id='imQhf'><fieldset id='imQhf'></fieldset></dl></div>

    2. <legend id='imQhf'><style id='imQhf'><dir id='imQhf'><q id='imQhf'></q></dir></style></legend>
        <bdo id='imQhf'></bdo><ul id='imQhf'></ul>

      <small id='imQhf'></small><noframes id='imQhf'>

    3. Android-listview、服务媒体播放器和布尔标志

      Android- listview, service mediaplayer, and boolean flags(Android-listview、服务媒体播放器和布尔标志)

        <bdo id='KDcUG'></bdo><ul id='KDcUG'></ul>
        • <legend id='KDcUG'><style id='KDcUG'><dir id='KDcUG'><q id='KDcUG'></q></dir></style></legend>
            <tbody id='KDcUG'></tbody>

                <i id='KDcUG'><tr id='KDcUG'><dt id='KDcUG'><q id='KDcUG'><span id='KDcUG'><b id='KDcUG'><form id='KDcUG'><ins id='KDcUG'></ins><ul id='KDcUG'></ul><sub id='KDcUG'></sub></form><legend id='KDcUG'></legend><bdo id='KDcUG'><pre id='KDcUG'><center id='KDcUG'></center></pre></bdo></b><th id='KDcUG'></th></span></q></dt></tr></i><div id='KDcUG'><tfoot id='KDcUG'></tfoot><dl id='KDcUG'><fieldset id='KDcUG'></fieldset></dl></div>
                <tfoot id='KDcUG'></tfoot>

                <small id='KDcUG'></small><noframes id='KDcUG'>

              1. 本文介绍了Android-listview、服务媒体播放器和布尔标志的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                问题描述

                我目前有一个 listview,当您单击一个项目时,它会运行一个带有 mediaplayerservice.如果我单击 listview 中的另一个项目,正在运行的 service 应该停止并运行新的 service.我正在使用 boolean isRunning 设置为 false,并且在创建服务时它返回 true.然后在 listview 中,我在 if 语句中调用该标志.但是,它并不完全有效.我想我可能做错了.有什么想法吗?

                I currently have a listview and when you click on an item it runs a service with a mediaplayer. If I click on another item in the listview the service that's running should stop and run the new service. I am using a boolean isRunning set to false and when the service is created it returns true. Then in the listview I call that flag in an if statement. However, its not exactly working. I think I may be doing this wrong. Any ideas?

                这听起来可能使我描述它的方式令人困惑,所以这是我的 listview 和我的 service 的代码.我只是在案例 3 上测试这个(所以我按下这个项目来启动服务,然后点击案例 2 看它是否会停止它).

                This probably sounds confusing the way I described it so Here is the code to my listview and my service. I am only testing this on case 3 (so I press this item to start the service and then click on case 2 to see if it will stop it).

                列表视图类:

                public class PlaylistActivity extends ListActivity{
                
                    private static final String TAG = PlaylistActivity.class.getSimpleName();
                
                    // Data to put in the ListAdapter
                    private String[] sdrPlaylistNames = new String[] {
                            "Best of June 2011", "Best of May 2011", "Dubstep",
                            "House", "Other"};
                
                    private ListAdapter sdrListAdapter;
                    Intent playbackServiceIntentBOJ, playbackServiceIntentBOM, playbackServiceIntentDUB;
                
                
                
                    @Override
                    public void onCreate(Bundle savedInstanceState) {
                        super.onCreate(savedInstanceState);
                        setContentView(R.layout.playlists_layout);
                        //fill the screen with the list adapter
                        playlistFillData();
                
                        playbackServiceIntentDUB = new Intent(this, DUBAudioService.class);
                        Log.d(TAG, "Made DUB Service Intent");
                    }
                
                    public void playlistFillData() {
                        //create and set up the Array adapter for the list view
                        ArrayAdapter sdrListAdapter = new ArrayAdapter(this, R.layout.list_item, sdrPlaylistNames);
                        setListAdapter(sdrListAdapter);
                    }
                
                    //set up the on list item Click 
                    @Override
                    protected void onListItemClick(ListView l, View v, int position, long id) {
                        super.onListItemClick(l, v, position, id);
                        //create a switch so that each list item is a different playlist
                        switch(position){
                        case 0:
                            Intent BOJintent = new Intent(this, BOJAudioActivity.class);
                            // Create the view using PlaylistGroup's LocalActivityManager
                            View view = PlaylistGroup.group.getLocalActivityManager()
                            .startActivity("show_city", BOJintent
                            .addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP))
                            .getDecorView();
                
                            // Again, replace the view
                            PlaylistGroup.group.replaceView(view);
                
                         //   playbackServiceIntentBOJ = new Intent(this, BOJAudioService.class);
                                Log.d(TAG, "Made BOJ Intent");
                        //  startService(playbackServiceIntentBOJ);
                                Log.d(TAG, "started BOJ Service");
                
                            break;
                        case 1:
                            Intent BOMintent = new Intent(this, BOMAudioActivity.class);
                            // Create the view using PlaylistGroup's LocalActivityManager
                            View view2 = PlaylistGroup.group.getLocalActivityManager()
                            .startActivity("show_city", BOMintent
                            .addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP))
                            .getDecorView();
                
                            // Again, replace the view
                           PlaylistGroup.group.replaceView(view2);
                                Log.d(TAG, "Replace view");
                
                                //getApplicationContext().stopService(playbackServiceIntentBOJ);
                
                            //playbackServiceIntentBOM = new Intent(this, BOJAudioService.class);
                                Log.d(TAG, "Made BOM Service Intent");
                        //  startService(playbackServiceIntentBOM);
                                Log.d(TAG, "started BOM Service");
                
                                if(DUBAudioActivity.isRunningDUB = true){
                                    stopService(playbackServiceIntentDUB);
                                    Log.d(TAG, "stop service isRunningDUB");
                                }
                //
                            break;
                        case 2:
                
                            Intent DUBIntent = new Intent (this, DUBAudioActivity.class);
                            View view3 = PlaylistGroup.group.getLocalActivityManager()
                                        .startActivity("show_city", DUBIntent
                                                .addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP))
                                                .getDecorView();
                            PlaylistGroup.group.replaceView(view3);
                                Log.d(TAG, "Replace view");
                
                            startService(playbackServiceIntentDUB);
                                Log.d(TAG, "started DUB service");
                
                            break;
                
                        }
                
                
                    }
                
                
                }
                

                服务类:

                public class DUBAudioService extends Service implements OnPreparedListener, OnCompletionListener{
                
                Toast loadingMessage;
                
                private static final String TAG = DUBAudioService.class.getSimpleName();
                
                    public static boolean isRunningDUB = false;
                
                    //to keep track of the playlist item
                    Vector<PlaylistFile> playlistItems;
                
                    MediaPlayer mediaPlayer;
                
                    String baseURL = "";
                
                    //keep track of which item from the vector we are on
                    int currentPlaylistltemNumber = 0;
                
                    public class DUBBackgroundAudioServiceBinder extends Binder {
                        DUBAudioService getService() {
                        return DUBAudioService.this;
                        }
                    }
                
                    private final IBinder basBinderDUB = new DUBBackgroundAudioServiceBinder();
                
                
                
                    @Override
                    public IBinder onBind(Intent intent) {
                        return basBinderDUB;
                    }
                
                    @Override
                    public void onCreate() {
                        Log.v("PLAYERSERVICE", "onCreate");
                        mediaPlayer = new MediaPlayer();
                        new MusicAsync().execute();
                            Log.d(TAG, "execute'd async");
                        mediaPlayer.setOnPreparedListener(this);
                            Log.d(TAG, "set on prepared listener");
                        mediaPlayer.setOnCompletionListener(this);
                            Log.d(TAG, "set on completion listener");
                
                            isRunningDUB = true;
                            Log.d(TAG, "isRunningRUB = true");
                    }
                
                    @Override
                    public int onStartCommand(Intent intent, int flags, int startId) {
                        //if (!mediaPlayer.isPlaying()) {
                        //  mediaPlayer.start();
                        /
                                
                本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

                相关文档推荐

                How can I use CClistview in COCOS2d Android?(如何在 COCOS2d Android 中使用 CClistview?)
                cocos2d-android: how to display score(cocos2d-android:如何显示分数)
                Sqlite database not copied from asset folder Android(Sqlite 数据库未从资产文件夹 Android 复制)
                SQLite Database Copy Appears Corrupted When Generated by Device and not Emulator(SQLite 数据库副本在由设备而不是模拟器生成时出现损坏)
                Android file copy(安卓文件拷贝)
                Android how to detect Copy event of Edittext in android(Android如何在android中检测Edittext的Copy事件)
                <tfoot id='5tzOG'></tfoot>

                <i id='5tzOG'><tr id='5tzOG'><dt id='5tzOG'><q id='5tzOG'><span id='5tzOG'><b id='5tzOG'><form id='5tzOG'><ins id='5tzOG'></ins><ul id='5tzOG'></ul><sub id='5tzOG'></sub></form><legend id='5tzOG'></legend><bdo id='5tzOG'><pre id='5tzOG'><center id='5tzOG'></center></pre></bdo></b><th id='5tzOG'></th></span></q></dt></tr></i><div id='5tzOG'><tfoot id='5tzOG'></tfoot><dl id='5tzOG'><fieldset id='5tzOG'></fieldset></dl></div>
                  • <small id='5tzOG'></small><noframes id='5tzOG'>

                        <bdo id='5tzOG'></bdo><ul id='5tzOG'></ul>
                            <tbody id='5tzOG'></tbody>
                          <legend id='5tzOG'><style id='5tzOG'><dir id='5tzOG'><q id='5tzOG'></q></dir></style></legend>