انجمن سایت کلیدستان


رتبه موضوع:
  • 0 رای - 0 میانگین
  • 1
  • 2
  • 3
  • 4
  • 5
توسعه کلید 359 (پخش فایل صوتی از اینترنت) (برنامه نویسی اندروید)

توسعه کلید 359 (پخش فایل صوتی از اینترنت) (برنامه نویسی اندروید)

#4
این کد :
کد پی‌اچ‌پی:
package com.kelidestan.mediaplayerplayback;

import java.io.IOException;


import android.app.Activity;
import android.media.AudioManager;
import android.media.MediaPlayer;
import android.os.Bundle;
import android.os.Handler;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.SeekBar;
import android.widget.Toast;
import android.widget.SeekBar.OnSeekBarChangeListener;
import android.widget.TextView;

public class 
MainActivity extends Activity implements OnClickListener {
    
    
SeekBar seek_bar;
    
Button play_buttonpause_button;
    
MediaPlayer mediaPlayer;
    
TextView text_shown;
    
Handler seekHandler = new Handler();
    
String url "http://android.programmerguru.com/wp-content/uploads/2013/04/hosannatelugu.mp3";
    static 
MediaPlayer mPlayer;

    @
Override
    
protected void onCreate(Bundle savedInstanceState) {
        
super.onCreate(savedInstanceState);
        
setContentView(R.layout.activity_main);
        
        
getInit();
        
seekUpdation();
    }

 
    public 
void getInit() {  
        
seek_bar = (SeekBarfindViewById(R.id.seek_bar);
        
play_button = (ButtonfindViewById(R.id.play_button);
        
pause_button = (ButtonfindViewById(R.id.pause_button);
        
text_shown = (TextViewfindViewById(R.id.text_shown);
        
play_button.setOnClickListener(this);
        
pause_button.setOnClickListener(this);
       
            
mPlayer = new MediaPlayer();
            
mPlayer.setAudioStreamType(AudioManager.STREAM_MUSIC);
            try {
                
mPlayer.setDataSource(url);
            } catch (
IllegalArgumentException e) {
                
Toast.makeText(getApplicationContext(),
                        
"You might not set the URI correctly!",
                        
Toast.LENGTH_LONG).show();
            } catch (
SecurityException e) {
                
Toast.makeText(getApplicationContext(),
                        
"You might not set the URI correctly!",
                        
Toast.LENGTH_LONG).show();
            } catch (
IllegalStateException e) {
                
Toast.makeText(getApplicationContext(),
                        
"You might not set the URI correctly!",
                        
Toast.LENGTH_LONG).show();
            } catch (
IOException e) {
                
e.printStackTrace();
            }
            try {
                
mPlayer.prepare();
            } catch (
IllegalStateException e) {
                
Toast.makeText(getApplicationContext(),
                        
"You might not set the URI correctly!",
                        
Toast.LENGTH_LONG).show();
            } catch (
IOException e) {
                
Toast.makeText(getApplicationContext(),
                        
"You might not set the URI correctly!",
                        
Toast.LENGTH_LONG).show();
            }
            
mPlayer.start();
        
    

    
pause_button = (ButtonfindViewById(R.id.pause_button);
    
pause_button.setOnClickListener(new OnClickListener() {

        public 
void onClick(View v) {
            
// TODO Auto-generated method stub
            
if (mPlayer != null && mPlayer.isPlaying()) {
                
mPlayer.stop();
            }
        }
    });


                
                
                

    }

    
Runnable run = new Runnable() {

        @
Override
        
public void run() {
            
seekUpdation();
        }
    };

    public 
void seekUpdation() {

        
seek_bar.setProgress(mediaPlayer.getCurrentPosition());
        
seekHandler.postDelayed(run1000);
        
seek_bar.setOnSeekBarChangeListener(new OnSeekBarChangeListener() {
            
            @
Override
            
public void onStopTrackingTouch(SeekBar seek_bar) {
                
// TODO Auto-generated method stub
                
            
}
            
            @
Override
            
public void onStartTrackingTouch(SeekBar seek_bar) {
                
// TODO Auto-generated method stub
                
            
}
            
            @
Override
            
public void onProgressChanged(SeekBar seek_barint progressboolean fromUser) {
                if(
fromUser){ 
                    
mediaPlayer.seekTo(progress); 
                    
seek_bar.setProgress(progress);
                }
                
            }
        });
    }

    @
Override
    
public void onClick(View view) {
        switch (
view.getId()) {
        case 
R.id.play_button:
            
text_shown.setText("Playing...");
            
mediaPlayer.start();
            break;
        case 
R.id.pause_button:
            
mediaPlayer.pause();
            
text_shown.setText("Paused...");
        }
    }
    
    public 
void onProgressChanged(SeekBar seekBarint progressboolean fromUser) { 
        if(
fromUser){ 
            
mediaPlayer.seekTo(progress); 
            
seekBar.setProgress(progress);
        }
    }
    
    
    @
Override
    
public void onBackPressed() {
        
mediaPlayer.stop();
        
finish();
    }
      

فایل رو از نت می گیره و پخش می کنه فقط نمی دونم چه جوری توش از سک بار استفاده کنم اگه کمکم کنید مشکلم حل میشه
پاسخ
 سپاس شده توسط شماره مجازی امارات ، تلگرام ضد فیلتر 2023


پیام‌های این موضوع
RE: توسعه کلید 359 - توسط apriliyaa - ۱۳۹۴/۰۸/۰۶, ۰۲:۰۹ ب.ظ
RE: توسعه کلید 359 (برنامه نویسی اندروید) - توسط admin - ۱۳۹۴/۰۸/۰۶, ۰۴:۴۱ ب.ظ
RE: توسعه کلید 359 (پخش فایل صوتی از اینترنت) (برنامه نویسی اندروید) - توسط apriliyaa - ۱۳۹۴/۰۸/۰۶, ۰۷:۲۳ ب.ظ

پرش به انجمن:


کاربران در حال بازدید این موضوع: 1 مهمان