Android 媒体:网络视频播放器的基本设计,女生学移动应用开发就业方向

            mMediaPlayer01.start();
            return;
        } else if (mMediaPlayer01 != null) {
            mMediaPlayer01.stop();
        }
        mCurrentFilePath = strPath;
        /* 重新构建MediaPlayer对象 */
        mMediaPlayer01 = new MediaPlayer();
        /* 设置播放音量 */
        mMediaPlayer01.setAudioStreamType(2);
        /* 设置显示于SurfaceHolder */
        mMediaPlayer01.setDisplay(mSurfaceHolder);
        mMediaPlayer01.setOnErrorListener
                (new MediaPlayer.OnErrorListener() {
                    @Override
                    public boolean onError(MediaPlayer mp, int what, int extra) {
                        Log.i(TAG, "Error on Listener, what: " + what + "extra: " + extra);
                        return false;
                    }
                });
        mMediaPlayer01.setOnBufferingUpdateListener
                (new MediaPlayer.OnBufferingUpdateListener() {
                    @Override
                    public void onBufferingUpdate(MediaPlayer mp, int percent) {
                        Log.i(TAG, "Update buffer: " + Integer.toString(percent) + "%");
                    }
                });
        mMediaPlayer01.setOnCompletionListener
                (new MediaPlayer.OnCompletionListener() {
                    @Override
                    public void onCompletion(MediaPlayer mp) {
                        Log.i(TAG, "mMediaPlayer01 Listener Completed");
                        mTextView.setText(R.string.str_done);
                    }
                });
        mMediaPlayer01.setOnPreparedListener
                (new MediaPlayer.OnPreparedListener() {
                    @Override
                    public void onPrepared(MediaPlayer mp) {
                        Log.i(TAG, "Prepared Listener");
                    }
                });
        Runnable r = new Runnable() {
            public void run() {
                try {
                    /* 在线程运行中,调用自定义函数抓下文件 */
                    setDataSource(strPath);
                    /* 下载完后才会调用prepare */
                    mMediaPlayer01.prepare();
                    Log.i(TAG, "Duration: " + mMediaPlayer01.getDuration());
                    mMediaPlayer01.start();
                    bIsReleased = false;
                } catch (Exception e) {
                    Log.e(TAG, e.getMessage(), e);
                }
            }
        };
        new Thread(r).start();
    } catch (Exception e) {
        if (mMediaPlayer01 != null) {
            mMediaPlayer01.stop();
            mMediaPlayer01.release();
        }
    }
}
/**
 * 自定义setDataSource,由线程启动
 */
private void setDataSource(String strPath) throws Exception {
    if (!URLUtil.isNetworkUrl(strPath)) {
        mMediaPlayer01.setDataSource(strPath);
    } else {
        if (bIsReleased == false) {
            URL myURL = new URL(strPath);
            URLConnection conn = myURL.openConnection();
            conn.connect();
            InputStream is = conn.getInputStream();
            if (is == null) {
                throw new RuntimeException("stream is null");
            }
            File myFileTemp = File.createTempFile
                    ("hippoplayertmp", "." + getFileExtension(strPath));
            currentTempFilePath = myFileTemp.getAbsolutePath();
            /*currentTempFilePath = /sdcard/mediaplayertmp39327.dat */
            FileOutputStream fos = new FileOutputStream(myFileTemp);
            byte buf[] = new byte[128];
            do {
                int numread = is.read(buf);
                if (numread <= 0) {
                    break;
                }
                fos.write(buf, 0, numread);
            } while (true);
            mMediaPlayer01.setDataSource(currentTempFilePath);
            try {
                is.close();
            } catch (Exception ex) {
                Log.e(TAG, "error: " + ex.getMessage(), ex);
            }
        }
    }
}
/**
 * 获取并返回文件扩展名
 *
 * @param strFileName 视频的链接
 */
private String getFileExtension(String strFileName) {
    File myFile = new File(strFileName);
    String strFileExtension = myFile.getName();
    strFileExtension = (strFileExtension.substring
            (strFileExtension.lastIndexOf(".") + 1)).toLowerCase();
    if (strFileExtension == "") {
        // 若无法顺利取得扩展名,默认为.dat
        strFileExtension = "dat";
    }
    return strFileExtension;
}
/**
 * 判断SD卡是否存在
 */
private boolean checkSDCard() {
    if (android.os.Environment.getExternalStorageState().equals
            (android.os.Environment.MEDIA_MOUNTED)) {
        return true;
    } else {
        return false;
    }
}
private void initViews() {
    mTextView = (TextView) findViewById(R.id.myTextView1);
    mEditText = (EditText) findViewById(R.id.myEditText1);
    mPlay = (ImageButton) findViewById(R.id.play);
    mReset = (ImageButton) findViewById(R.id.reset);
    mPause = (ImageButton) findViewById(R.id.pause);
    mStop = (ImageButton) findViewById(R.id.stop);
    /* 绑定Layout上的SurfaceView */
    mSurfaceView = (SurfaceView) findViewById(R.id.mSurfaceView1);
}
@Override
public void surfaceChanged
        (SurfaceHolder surfaceholder, int format, int w, int h) {
    Log.i(TAG, "Surface Changed");
}
@Override
public void surfaceCreated(SurfaceHolder surfaceholder) {
    Log.i(TAG, "Surface Changed");
}
@Override
public void surfaceDestroyed(SurfaceHolder surfaceholder) {
    Log.i(TAG, "Surface Changed");
}

}

activity_main.xml:


<?xml version="1.0" encoding="utf-8"?>

<LinearLayout

xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="@drawable/white"
android:orientation="vertical"
android:padding="16dp"
>
<TextView
    android:id="@+id/myTextView1"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:text="@string/hello"
    android:textColor="@drawable/blue"/>
<EditText
    android:id="@+id/myEditText1"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:singleLine="true"
    android:textColor="#0000ff"
    android:text=""/>
<SurfaceView
    android:id="@+id/mSurfaceView1"
    android:layout_width="320px"
    android:layout_height="240px"
    android:layout_margin="16dp"
    android:visibility="visible">
</SurfaceView>
<LinearLayout
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:orientation="horizontal"
    android:padding="10dip"
    >
    <ImageButton
        android:id="@+id/play"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:src="@drawable/play"
        />
    <ImageButton
        android:id="@+id/pause"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:src="@drawable/pause"
        />
    <ImageButton
        android:id="@+id/reset"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"

自我介绍一下,小编13年上海交大毕业,曾经在小公司待过,也去过华为、OPPO等大厂,18年进入阿里一直到现在。

深知大多数Android工程师,想要提升技能,往往是自己摸索成长或者是报班学习,但对于培训机构动则几千的学费,着实压力不小。自己不成体系的自学效果低效又漫长,而且极易碰到天花板技术停滞不前!

因此收集整理了一份《2024年Android移动开发全套学习资料》,初衷也很简单,就是希望能够帮助到想自学提升又不知道该从何学起的朋友,同时减轻大家的负担。
img
img
img
img
img
img
img

既有适合小白学习的零基础资料,也有适合3年以上经验的小伙伴深入学习提升的进阶课程,基本涵盖了95%以上Android开发知识点,真正体系化!

由于文件比较大,这里只是将部分目录大纲截图出来,每个节点里面都包含大厂面经、学习笔记、源码讲义、实战项目、讲解视频,并且后续会持续更新

如果你觉得这些内容对你有帮助,可以添加V获取:vip204888 (备注Android)
img

文末

好了,今天的分享就到这里,如果你对在面试中遇到的问题,或者刚毕业及工作几年迷茫不知道该如何准备面试并突破现状提升自己,对于自己的未来还不够了解不知道给如何规划,可以来看看同行们都是如何突破现状,怎么学习的,来吸收他们的面试以及工作经验完善自己的之后的面试计划及职业规划。

这里放上一部分我工作以来以及参与过的大大小小的面试收集总结出来的一套进阶学习的视频及面试专题资料包,主要还是希望大家在如今大环境不好的情况下面试能够顺利一点,希望可以帮助到大家

一个人可以走的很快,但一群人才能走的更远。不论你是正从事IT行业的老鸟或是对IT行业感兴趣的新人,都欢迎扫码加入我们的的圈子(技术交流、学习资源、职场吐槽、大厂内推、面试辅导),让我们一起学习成长!
img
取:vip204888 (备注Android)**
[外链图片转存中…(img-1jAVjQT8-1712769356840)]

文末

好了,今天的分享就到这里,如果你对在面试中遇到的问题,或者刚毕业及工作几年迷茫不知道该如何准备面试并突破现状提升自己,对于自己的未来还不够了解不知道给如何规划,可以来看看同行们都是如何突破现状,怎么学习的,来吸收他们的面试以及工作经验完善自己的之后的面试计划及职业规划。

这里放上一部分我工作以来以及参与过的大大小小的面试收集总结出来的一套进阶学习的视频及面试专题资料包,主要还是希望大家在如今大环境不好的情况下面试能够顺利一点,希望可以帮助到大家

[外链图片转存中…(img-Z1TbLgtM-1712769356840)]

一个人可以走的很快,但一群人才能走的更远。不论你是正从事IT行业的老鸟或是对IT行业感兴趣的新人,都欢迎扫码加入我们的的圈子(技术交流、学习资源、职场吐槽、大厂内推、面试辅导),让我们一起学习成长!
[外链图片转存中…(img-cP7aQu1a-1712769356840)]

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值